I'm trying to write a query to return unique cities. My code is:
GET /files/_doc/_search
{
"size":"0",
"aggs" : {
"uniq_cities" : {
"terms" : { "field" : "cities" }
}
}
}
I have an error message as follows:
Fielddata is disabled on text fields by default. Set fielddata=true on [cities] 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.
When I run
GET /files/_doc/_mapping
I get:
"cities" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
Based on the above, it seems that I already have a keyword field. How do I fix the error message?