首页 文章

elasticsearch 5.2使用ICU插件进行排序需要fielddata = true吗?

提问于
浏览
0

我想用icu_collation过滤器对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_collation without fielddata = true?

谢谢 .

1 回答

  • 0

    在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
            }
          }
        }
      }
    }'
    

相关问题