【发布时间】:2017-08-16 23:30:55
【问题描述】:
在使用 bool 和 must 查询时,尝试让 python-elasticsearch 或 curl 返回适当的结果。
我知道文档在我的查询中,我可以用“应该”找到它;但是,我需要同时满足这两个条件,所以我尝试使用“必须”进行相同的查询。当我使用“必须”时,相关文档不会返回。
应有
$ 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 的评论中,或者您可以将您的映射从文本类型更改为关键字类型,然后它将匹配术语作为其确切值
标签: python elasticsearch