【问题标题】:Convert intervals query to the earlier version that doesn't support it将间隔查询转换为不支持它的早期版本
【发布时间】:2021-10-03 11:26:42
【问题描述】:

我有一个 ES 查询,它是用支持intervals 查询的更新版本的 ES 编写的。 但我想将这个包含intervals 的简单查询转换为在不支持intervals 的早期版本6 上运行的查询

GET /myindex/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "intervals": {
            "title_en": {
              "match": {
                "query": "title phrase in en",
                "max_gaps": -1,
                "ordered": true
              }
            }
          }
        },
        {
          "intervals": {
            "title_de": {
              "match": {
                "query": "title phrase in de",
                "max_gaps": -1,
                "ordered": true
              }
            }
          }
        }
      ],
      "minimum_should_match" : 1,
      "filter": [
        {
          "terms": {"status.id": [1,2]}
        }
      ]
    }
  }
}

我想我应该用query_string 解决它。 我写了这样的东西(部分):

{
    "query_string": {
      "default_field": "title_en",
      "query": "\"title phrase in en\"~3"
    }
}

但我认为这不是正确的解决方案。

【问题讨论】:

  • 你用的是哪个版本的?
  • 我需要在 6.2.2 版本上运行它
  • 有没有办法删除区间查询并进行转换?

标签: elasticsearch elastic-stack


【解决方案1】:

以下查询允许获得类似于intervals 的结果。

intervals 替换为 match_phrase 并使用 slop

slop 值可以配置为允许我们控制查询词之间可以放置多少个词。

所以查询是:

GET /myindex/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "title_en": {
              "query": "title phrase in en",
              "slop": 5
            }
          }
        },
        {
          "match_phrase": {
            "title_de": {
              "query": "title phrase in de",
              "slop": 5
            }
          }
        }
      ],
      "minimum_should_match" : 1,
      "filter": [
        {
          "terms": {"status.id": [1,2]}
        }
      ]
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2020-12-11
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    相关资源
    最近更新 更多