elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合]
在我的映射中有这个字段elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合],elasticsearch,mapping,aggregation,elasticsearch,Mapping,Aggregation,在我的映射中有这个字段 "answer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, 我尝试执行这个聚合 "aggs": { "answer": { "terms": { "field": "answe
"answer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
我尝试执行这个聚合
"aggs": {
"answer": {
"terms": {
"field": "answer"
}
},
但是我得到了这个错误
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [answer] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
我必须更改映射还是使用了错误的聚合?(刚刚从2.x更新到5.1)您需要在
关键字
子字段上进行聚合,如下所示:
"aggs": {
"answer": {
"terms": {
"field": "answer.keyword"
}
},
这就行了。除了@Val的答案之外,您还可以在映射过程中将
字段数据设置为true:
"answer": {
"type": "text",
"fielddata": true, <-- add this line
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
“答案”:{
“类型”:“文本”,
“fielddata”:是的,在聚合中,只需添加关键字即可回答。这对我很有效。对于文本字段,我们需要添加关键字。
“字段”:“answer.keyword”我不确定是否接受任何fielddata
设置,就像text
类型一样。根据例外情况(Set fielddata=true on[answer]
),我认为问题出在提供的映射中的答案
。这是因为他在答案
上聚合,但他最好在答案.关键字
上聚合,因为他有那个字段。