【问题标题】:How to convert this elasticsearch query from 2.x to 5.x index?如何将此 elasticsearch 查询从 2.x 转换为 5.x 索引?
【发布时间】:2018-10-17 16:28:35
【问题描述】:

我们的系统将 elasticsearch 从 2.x 升级到 5.x。 现在查询在用 2.x 编写的 5.x 中不起作用。 所以我必须将 elasticsearch 查询从 2.x 转换为 5.x 索引?

请建议如何将此查询转换为 elasticsearch 5.x 查询? _score 字段不会受到影响,并且能够缓存此查询。

{
  "size": 12,
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "pageType": "ulp_comb"
              }
            },
            {
              "range": {
                "date": {
                  "gte": "2017-09"
                }
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "entityId": 0
              }
            }
          ]
        }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    您只需将filtered 更改为bool

    {
      "size": 12,
      "query": {
        "bool": { // change to bool
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "pageType": "ulp_comb"
                  }
                },
                {
                  "range": {
                    "date": {
                      "gte": "2017-09"
                    }
                  }
                }
              ],
              "must_not": [
                {
                  "term": {
                    "entityId": 0
                  }
                }
              ]
            }
          }
        }
      }
    }
    

    希望对你有帮助

    【讨论】:

    猜你喜欢
    • 2018-07-08
    • 2021-05-02
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多