Text fields are not optimised for operations that require per-document field data like aggregations and sorting,

es执行如下命令报错 ``` #脚本字段 这个执行报错没明白啥原因 GET wenda_content/_search { "script_fields": { "new_field": { "script": { "lang": "painless", "source": "doc['title'].value+'hello'" } } }, "query": { "match_all": {} } } ``` 报如下错误: > Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [title] in order to load field data by uninverting the inverted index. Note that this can use significant memory. 谷歌翻译如下: > 文本字段并未针对需要每个文档字段数据的操作(例如聚合和排序)进行优化,因此默认情况下将禁用这些操作。 请改用关键字字段。 或者,在[title]上设置fielddata = true,以通过反转取反的索引来加载字段数据。 请注意,这可能会占用大量内存。 没明白啥意思?求解?

1 个回答

  • 大小姐
    重新审视自己,什么使你快乐,什么就是眼下最珍贵。
    执行如下命令就好了: ``` PUT /wenda_content/_mapping?pretty { "properties": { "title": { "type": "text", "fielddata": true } } } ``` 原因: 原因, 默认 Elasticsearch 对 text 类型的字段是不可聚合的,基本类型可聚合 如果 Fielddata = true 无法解决, 使用使用keyword
    编辑于 2021-05-24 21:39 •IP属地 天津
    已采纳
    举报
    评论
    收藏