简体   繁体   English

带有过滤条件和字符串搜索的Elasticsearch Bool查询返回不一致的结果

[英]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. 我正在对Elasticsearch运行以下查询,该查询基于字符串搜索和属性项匹配来匹配文档。 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 (ie 1,4,8), but when I pass all three userIDs I have several docIDs missing from the results (ie 1, 6, 8, but no 4). 如果我仅传递userID 1,而忽略其他ID,则将获得期望的docID(即1,4,8),但是当我传递所有三个userID时,结果中将缺少几个docID(即1,6,8,但没有4)。 Using Elasticsearch 6.5. 使用Elasticsearch 6.5。

Hopefully someone understands better than I why this is! 希望有人能比我理解得更好!

Thanks in advance! 提前致谢!

By default, ES returns result as 10. Maybe the missing documents are in the next page. 默认情况下,ES返回结果为10。也许丢失的文档在下一页中。 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"
            ]
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM