Bool query with must query is matching all documents when the query doesn't match

Hi,

i am using 5.x version of elasticsearch. my loaded documents are:

POST index1/_bulk
{ "index" : {"_type" : "type1", "_id" : "1" } }
{"name": "sahana","rollno": "123456","class": "first"}
{ "index" : {"_type" : "type1", "_id" : "2" } }
{"name": "sahana","rollno": "654321","class": "first"}

and my query having must operator query:

"query": {"bool":{"must":[{"term":{"name":"sahana"}},{"term":{"rollno":"123456"}}]}}

and my get request on above documents:
GET index1/_search

i am seeing an issue where if a query, such as a simple_query_string used in must clause of a bool query, and the analyzed query string results in an empty query string, then the it behaves like the entire query is ignored and all documents are matched. Even if the simple_query_string. query is inside a filtered query, then the filters are ignored. i am expecting the document with id 1 only for this.

any ideas or help on this would be much appreciated.

Note: i am also tried with query_string query, but still able to get the all the documents

as you can see i use the simple_query_string query. but i dont know somehow its still returning the both 2 docs.

{
"query" : {
  "bool" : {
    "must" : [
      {
        "match_all" : {
          "boost" : 1.0
        }
      }
    ],
    "filter" : [
      {
        "bool" : {
          "must" : [
            {
              "indices" : {
                "indices" : [
                  "index1"
                ],
                "query" : {
                  "simple_query_string" : {
                    "query" : "{\"bool\":{\"must\":[{\"term\":{\"name\":\"sahana\"}},{\"term\":{\"rollno\":\"123456\"}}]}}",
                    "flags" : -1,
                    "default_operator" : "or",
                    "lenient" : false,
                    "analyze_wildcard" : false,
                    "boost" : 1.0
                  }
                },
                "no_match_query" : {
                  "match_all" : {
                    "boost" : 1.0
                  }
                },
                "boost" : 1.0
              }
            }
          ],
          "disable_coord" : false,
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "disable_coord" : false,
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
},
  "ext" : { }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.