Search code examples
elasticsearchbooleanquery

Elasticsearch different results with boolean queries


I have two queries that I think, should return same amount of results. First is a "must" with query_string on 2 fields. E.g.

{
  "query": {
    "nested": {
      "path": "app.pub",
      "query": {
        "bool": {
          "must": [
            {
              "query_string": {
                "query": "wheel* chair* foot* driven*",
                "fields": [
                  "app.pub.title.*.docdba",
                  "app.pub.abstract.*.docdba"
                ],
                "default_operator": "and"
              }
            }
          ]
        }
      }
    }
  }
}

That gives me 120 results. Second one is a "should" query, that searches for same strings with wildcards, on title field or abstract. E.g.:

{
  "query": {
    "nested": {
      "path": "app.pub",
      "query": {
        "bool": {
          "should": [
            {
              "query_string": {
                "query": "wheel* chair* foot* driven*",
                "fields": [
                  "app.pub.title.*.docdba"
                ],
                "default_operator": "and"
              }
            },
            {
              "query_string": {
                "query": "wheel* chair* foot* driven*",
                "fields": [
                  "app.pub.abstract.*.docdba"
                ],
                "default_operator": "and"
              }
            }
          ]
        }
      }
    }
  }
}

Here I'm getting 109 results. So I have 11 hits less. Anyone have idea why?


Solution

  • Easy. In first search I'm looking for 4 words in two fields. That means it matches fields that does not have all searched words in one field, but also combination of two. While in second search all 4 words have to be present in one field or another.