Trying to use Aggregate, "Fielddata is disabled on text fields by default. Set fielddata=true"

ElasticSearch version: 6.6
Language: PHP

Hello and good day! I'm using Laravel PHP Framework and ElasticSearch as our database / search engine.

In my Index, I'm trying to get a list of Authors who had produced the most Articles, here's my parameters:

$params = [
		'index' => 'mmi.webs',
		'type'	=> '_doc',
		"from"  => '0', //default 0
		"size"  => '10', //default 10
		'body'	=> [
		    'aggs' => [
				'authors' => [
					'terms' => [
						'field' => 'author_id',
						'size' => 25,
						'order' => [ '_term' => 'asc' ]
					]
				],
			]
		]
	];

But unfortunately it returns this error according to my author_id, ""Fielddata is disabled on text fields by default. Set fielddata=true".

I've searched for different solutions, and some said turn on the "keyword" something, but according to the mapping of my index, keywords are already enabled

"author_id" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },

So why is it still not working?

Run your aggregation on author_id.keyword instead.

hello sir @dadoonet, thank you for the fast response!

may I know how to run my aggregation on author_id.keyword? is it supposed to look like this?

'aggs' => [
				'authors' => [
					'terms' => [
						'field' => 'author_id.keyword',
						'size' => 25,
						'order' => [ '_term' => 'asc' ]
					]
				],
			]

If it is correct, I've started retrieving buckets!

Again, thank you very much, appreciate it! :smiley:

Yes.

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