【问题标题】:elasticsearch 5.2 sorting with ICU plugin needs fielddata = true?elasticsearch 5.2 使用 ICU 插件进行排序需要 fielddata = true?
【发布时间】:2017-06-30 08:30:37
【问题描述】:

我想使用 icu_collat​​ion 过滤器对 elasticsearch 结果文档进行排序。所以我有 索引设置:

"settings": {
    "analysis": {
      "analyzer": {
        "ducet_sort": {
          "tokenizer": "keyword",
          "filter": [ "icu_collation" ]
        }
      }
    }
  }

和映射

"mappings": {
    "card": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "sort": {
              "type": "text",
              "analyzer": "ducet_sort",
              "index": false
            }
          }
        }
}}}

和查询:

{
      "sort": ["title.sort"]
}

但是查询失败:

"caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [title.sort] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
        }

在文档中,建议的排序数据类型是 keyword。但是数据类型 keyword 不支持分析器。另外不推荐使用fielddata:

documentation

那么有没有一种方法可以在弹性搜索中使用一些特定的排序规则对文档进行排序,例如icu_collat​​ion 没有 fielddata=true?

谢谢。

【问题讨论】:

标签: elasticsearch


【解决方案1】:

在 Kibana 中,从左侧菜单中打开 Dev Tools 选项,并根据您的设置在更新后执行下面的查询。

PUT _mapping/INDEX_NAME?update_all_types
{
  "properties": {
    "FIELD_NAME": {
      "type":     "text",
      "fielddata": true
    }
  }
}

或者通过Curl或者像Cygwin这样的终端(对于Windows)根据你的设置在更新后执行下面的查询。

curl -XPUT http://DOCKER_MACHINE_IP:9200/INDEX_NAME -d '{
  "mappings": {
    "type": {
      "properties": {
        "FIELD_NAME": {
          "type": "text",
          "fielddata": true
        }
      }
    }
  }
}'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多