Reputation: 3282
Every time I execute an aggregation command involving a text field, I get an error saying I need to enable Fielddate on textfields. Here's the query i'm executing:
GET customers/external/_search
{
"aggs": {
"group_by_date": {
"terms": {
"field": "city"
}
}
}
}
The official error that I am getting is:
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
So I try to enable Fielddata by executing this query:
PUT customers/external/text
{
"properties": {
"city": {
"type": "text",
"fielddata": true
}
}
}
Afterwards, I try to execute the aggregations query, but it still displays the same error message. I then try to execute this query:
PUT customers/external/text
{
"text": {
"properties": {
"publisher": {
"type": "text",
"fielddata": true
}
}
}
}
I then execute the aggregations query, but it still displays the same message. What am I doing wrong?
Upvotes: 0
Views: 206
Reputation: 10859
Your query to enable field data looks wrong to me. I've created a minimal example including GET customers/external/_mapping
calls to check the actual mapping:
PUT customers/external/1
{
"city": "San Francisco"
}
PUT customers/external/2
{
"city": "San Antonio"
}
GET customers/external/_mapping
PUT customers/_mapping/external
{
"properties": {
"city": {
"type": "text",
"fielddata": true
}
}
}
GET customers/external/_mapping
GET customers/external/_search
{
"aggs": {
"group_by_date": {
"terms": {
"field": "city"
}
}
}
}
DELETE customers
BUT this example also shows why you probably don't want to do that — you have two hits on "san" and that doesn't make much sense. Check out the docs why you probably want to use a keyword
for this functionality.
Upvotes: 1