【问题标题】:Elastic Search: ngram filter with aggregation弹性搜索:具有聚合的 ngram 过滤器
【发布时间】:2016-08-10 17:36:52
【问题描述】:

进行聚合时有什么方法可以超越 nGram 过滤器?

我有一个定义的 ngram 过滤器:

 "ngram_filter": {
          "type": "ngram",
          "min_gram": "1",
          "max_gram": "100"
        }

我想对一个定义了这个过滤器的字段进行聚合:

我得到桶结果过滤:

   "buckets": [
        {
          "key": "_",
          "doc_count": 394
        },
        {
          "key": "a",
          "doc_count": 365
        },
        {
          "key": "m",
          "doc_count": 357
        },
        {
          "key": "i",
          "doc_count": 344
        },
        {
          "key": "_d",
          "doc_count": 341
        },
        {
          "key": "d",
          "doc_count": 341
        },
        {
          "key": "e",
          "doc_count": 319
        },
        {
          "key": "r",
          "doc_count": 289
        },
        {
          "key": "l",
          "doc_count": 260
        },
        {
          "key": "l_",
          "doc_count": 221
        }
    ]

我也不想更改 ngram 分析器...

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    对于您设置了自定义 nGram 分析器的该字段,您需要添加一个应保留“原始”术语的子字段(使用 standard 分析器或字段应为 not_analyzed)或你想要在你的聚合中。那么你的聚合应该指向你的field.sub_field 字段。

    好的,试试这个次优的解决方案(因为它与子字段方法相比有多快),而不更改映射:

    {
      "aggs": {
        "whatever": {
          "terms": {
            "script": "_source['yourFieldName']"
          }
        }
      }
    }
    

    【讨论】:

    • 我无法更改 ngram 分析器或字段的映射...我需要一种方法来构建 es 查询以使聚合超过分析器...谢谢
    • 用次优解决方案更新了我的答案。
    • thx... 脚本解决方案将更容易加强更改映射的点:)
    猜你喜欢
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多