试图在使用bool和必须查询时获取python-elasticsearch或curl以返回适当的结果。Elasticsearch必须使用多个条件进行查询
我知道文档在我的查询中,我可以用'should'找到它;但是,我需要满足这两个标准,所以我尝试使用'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" : [ ] } }
很确定这是因为'project'字段被分析过(即它具有'text'类型)。你可以切换到使用'match'查询,或者使用'term',但是用小写而不是'AMQ'搜索'amq'。 – Val
添加到Val的注释上面,或者你可以改变你的从文本类型到关键字的映射键入然后它将匹配条款作为其确切的价值 – Rahul