TChadwick
TChadwick

Reputation: 878

Elasticsearch bool query with filter terms and string search returning inconsistent results

I'm running the following query against Elasticsearch that matches documents based on a string search and property terms match. When I pass a single term, I get the expected results, but when I add a second term, I don't get the same results. Ideas?

{
  "_source": {
    "includes": [
      "docID"
    ]
  },
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "userID": [
              1,
              2,
              71
            ]
          }
        },
        {
          "query_string": {
            "query": "**test**",
            "fields": [
              "attachment.content"
            ]
          }
        }
      ]
    }
  }
}

If I pass only userID 1, and omit the others, I get the docIDs I expect (i.e. 1,4,8), but when I pass all three userIDs I have several docIDs missing from the results (i.e. 1, 6, 8, but no 4). Using Elasticsearch 6.5.

Hopefully someone understands better than I why this is!

Thanks in advance!

Upvotes: 0

Views: 116

Answers (1)

deerawan
deerawan

Reputation: 8443

By default, ES returns result as 10. Maybe the missing documents are in the next page. We can increase the size to larger number such as:

{
  "size": 30, // put size here
  "_source": {
    "includes": [
      "docID"
    ]
  },
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "userID": [
              1,
              2,
              71
            ]
          }
        },
        {
          "query_string": {
            "query": "**test**",
            "fields": [
              "attachment.content"
            ]
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions