0
votes

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!

1
how many results that you got using three userIDs? by default, ES returns result as 10. Maybe your missing documents are in the next page.deerawan
Didn't know about the default of 10, thank you!!! Feel free to add it as an answer and I will mark it.TChadwick

1 Answers

1
votes

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"
            ]
          }
        }
      ]
    }
  }
}