A question about aggregation of ElasticSearch 5.x

Dear friends
I have a question about ElasticSearch 5.x while I am studying.Now I had sucessfully inserted some data into my ElasticSearch server like this
"
PUT /megacorp/employee/3
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets",
"interests": [ "forestry" ]
}
"

and I want to do some terms aggregation work like this
"
GET /megacorp/employee/_search
{
"aggs" : {
"last_names" : {
"terms" : { "field" : "last_name" }
}
}
}
"
but the server return some error infomation to me below
"
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [last_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "megacorp",
"node": "kDADT13zSoSzS2ioRMiAlQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [last_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [last_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
},
"status": 400
}
"

Could you give some help to resolve it ? Thannk you.

Can you show us the current mapping?
Probably using last_name.keyword can work.

the current mapping below

{
"megacorp": {
"mappings": {
"employee": {
"properties": {
"about": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"age": {
"type": "long"
},
"aggs": {
"properties": {
"last_names": {
"properties": {
"terms": {
"properties": {
"field": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
},
"first_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"interests": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"last_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"publisher": {
"type": "text",
"fielddata": true
}
}
}
}
}
}

So use the field I told you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.