1,运行如下聚合函数时报错: illegal_argument_exception
GET /megacorp/employee/_search
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}
问题出在5.x版本后对排序、聚合等操作为单独的数据结构缓存到内存里了,需要手动开启,官方文档作了说明:
https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html
根据文档要求,我们在这里应该执行
PUT megacorp/_mapping/employee/
{
"properties": {
"interests": {
"type": "text",
"fielddata": true
}
}
}
执行之后,该字段interests就可以使用聚合函数了,比如all_interests,avg_interests等等