0
votes

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" : [ ]   } }
1
pretty sure it is because the project field is analyzed (i.e. it has text type). You can either switch to using the match query instead, or stick with term but search for amq in lowercase instead of AMQVal
Adding to Val's comment above, or you can change your mapping from text type to keyword type then it will match the terms as its exact valueRahul

1 Answers

0
votes

change

{"term": {"project": "AMQ"}}

to

{"term": {"project": "amq"}}

OR we can substitute term with match and use 'AMQ'.

{"match": {"project": "AMQ"}}