{ "query": { "bool": { "must": { "term": { "type.keyword": "test" } } } }, "from": 0, "size": 0, "sort": [ { "msg_time": { "order": "desc" } } ], "aggs": { "myName": { "terms": { "field": "xxxx" } } } }
报错信息如下:
Fielddata is disabled on text fields by default. Set fielddata=true on [title] 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.
使用ES版本为:5.1.1
解决办法:
PUT my-index-000001/_mapping/type { "properties": { "my_field": { "type": "text", "fielddata": true } } }
最新版本不需要type
PUT my-index-000001/_mapping { "properties": { "my_field": { "type": "text", "fielddata": true } } }