尝试使用python-elasticsearch或curl在使用bool时返回相应的结果,并且必须查询。
我知道该文档在我的查询中,我可以用'应该&#39 ;;但是,我需要满足这两个标准,所以我尝试使用' must'进行相同的查询。当我使用' must'有问题的文件不予退还。
应该
$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"should" : [
{ "term" : {"project" : "AMQ"}},
{ "term" : {"test-type" : "functional"}}]
}
}
}
}
}
'
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [
{
"_index" : "polarion",
"_type" : "subtype1",
"_id" : "AV3s-vbF8T4AI9Zj3GkM",
"_score" : 1.0,
"_source" : {
"project" : "AMQ",
"query" : "test-metrics",
"test-type" : "functional",
"2017-08-16" : 1916
}
},
必须
$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"project" : "AMQ"}},
{ "term" : {"test-type" : "functional"}}]
}
}
}
}
}
'
{ "took" : 0, "timed_out" : false, "_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0 }, "hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ] } }
答案 0 :(得分:0)
变化
{"term": {"project": "AMQ"}}
到
{"term": {"project": "amq"}}
或者我们可以用匹配替换术语并使用'AMQ'。
{"match": {"project": "AMQ"}}