[英]How to fix ElasticSearch ‘Fielddata is disabled on text fields by default’ for keyword field
I'm getting the "Fielddata is disabled on text fields by default" on a keyword field.我在关键字字段上收到“默认情况下在文本字段上禁用字段数据”。 Below is the code.
下面是代码。
{
"aggs": {
"agg_terms_user": {
"terms": {
"field": "user"
}
}
}
}
The mapping for the user field is as below用户字段的映射如下
user: { type: "keyword" }
Since the user field has type set as keyword I shouldn't get the error.由于用户字段的类型设置为关键字,我不应该得到错误。 However, the error is still thrown.
但是,错误仍然被抛出。
[illegal_argument_exception] Fielddata is disabled on text fields by default.
[illegal_argument_exception] 默认情况下,在文本字段上禁用字段数据。 Set fielddata=true on [user] in order to load fielddata in memory by uninverting the inverted index.
在 [user] 上设置 fielddata=true,以便通过反转倒排索引将 fielddata 加载到内存中。 Note that this can however use significant memory.
请注意,这可能会占用大量内存。 Alternatively use a keyword field instead.
或者,改用关键字字段。
I don't know what to try now.我不知道现在该尝试什么。
The comment of @Andrey Borisko was correct @Andrey Borisko 的评论是正确的
I used我用了
"field": "user.keyword"
instead of代替
"field": "user"
based on Nikhil's example and it worked for me.基于 Nikhil 的示例,它对我有用。
I found the reason behind the unexpected error.我找到了意外错误背后的原因。 The ES wasn't getting re-indexed properly.
ES 没有得到正确的重新索引。 Once I deleted the indexed first and then recreated it then it started working like a charm.
一旦我先删除了索引然后重新创建它,它就开始像魅力一样工作。
Check out the documentation in the elastic which clearly mentions that we cannot use the text field for aggregations, sorting, or scripting查看 elastic 中的文档,其中明确提到我们不能将文本字段用于聚合、排序或脚本
https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#fielddata-mapping-param https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#fielddata-mapping-param
This can be achieved with help of keyword usage.这可以在关键字使用的帮助下实现。 Try searching by
尝试搜索
"field" : "user.keyword" “字段”:“user.keyword”
Facing the same issue in heartbeat application.I have solved this issue by following below steps.在心跳应用程序中面临同样的问题。我通过以下步骤解决了这个问题。
stop the application [ in my case I stopped the heartbeat application]停止应用程序[在我的情况下,我停止了心跳应用程序]
Delete the index related to apps.删除与应用程序相关的索引。
Start the application启动应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.