Trying to get python-elasticsearch or curl to return the appropriate results when using bool and must queries.
I know the document is in my query, I can find it with 'should'; however, I need both criteria to be satisfied so I try to do the same query with 'must'. When I use 'must' the document in question is not returned.
With Should
$ 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
}
},
With Must
$ 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
field is analyzed (i.e. it hastext
type). You can either switch to using thematch
query instead, or stick withterm
but search foramq
in lowercase instead ofAMQ
– Val