【问题标题】:Elasticsearch bool query with filter terms and string search returning inconsistent results带有过滤条件和字符串搜索的 Elasticsearch bool 查询返回不一致的结果
【发布时间】:2018-12-05 23:55:18
【问题描述】:

我正在针对 Elasticsearch 运行以下查询,该查询基于字符串搜索和属性术语匹配来匹配文档。当我通过一个术语时,我得到了预期的结果,但是当我添加第二个术语时,我没有得到相同的结果。想法?

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

如果我只传递 userID 1,而忽略其他的,我会得到我期望的 docID(即 1、4、8),但是当我传递所有三个 userID 时,结果中缺少几个 docID(即 1、6 , 8, 但没有 4)。使用 Elasticsearch 6.5。

希望有人比我更了解这是为什么!

提前致谢!

【问题讨论】:

  • 您使用三个用户 ID 获得了多少结果?默认情况下,ES 返回结果为 10。也许您丢失的文档在下一页中。
  • 不知道默认10,谢谢!!!随意添加它作为答案,我会标记它。

标签: elasticsearch


【解决方案1】:

默认情况下,ES 返回结果为 10。可能缺少的文档在下一页。我们可以将大小增加到更大的数字,例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 2020-07-24
    • 2020-10-20
    相关资源
    最近更新 更多