Elastic报错:Fielddata is disabled on text fields by default

Elastic 报错: 
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [state] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "bank",
"node": "HuFlhO8OSLSGr3RP6J2z6Q",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [state] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
]
},
"status": 400
}

 
解决办法:
查询的时候添加keyword
 
如上面的查询使用的是:
{"size":0,
"aggs":{"group_by_state":
{
"terms":{"field":"state"}
}}
}

就会报错。
 
使用下面的语句就不会错误了
{"size":0,
"aggs":{"group_by_state":
{
"terms":{"field":"state.keyword"}
}}
}
 
原文链接:
http://30daydo.com/article/366
 

3 个评论

老板破后台接不接
http://www.wkfml.xyz/mobile/
加我啊
嚯,写的很不错。
帮楼主补充一些,有挺多原因导致这个错误的。
具体可以看这篇文章「ES 如何解决 Fielddata is disabled on text fields by default 错误」
https://kalasearch.cn/community/tutorials/elasticsearch-fielddata-is-disabled-on-text-fields-error/
收到,谢谢~~~~~~

要回复文章请先登录注册