Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Search group by a text field throws error Fielddata is disabled on text fields by default

I am new to elastic search, as of now i have a requirement cause of which i need to group by a text field.

Now the most common answer to this question is to enable field data on an existing text field using the PUT mapping API.

Is there a simpler way to account for this situation without updating a template or index.

sample query:

GET ****/message/_search
        {
          "_source": ["identifier"],
          "size": 0,
          "aggs": {
            "group_by_coll_conv": {
              "terms": {
                "field": "identifier"
              },
              "aggs": {
                "count" : {
                  "value_count" : 
                    { 
                      "field" : "something" 
                    } 
                }
              }
            }
          }

Any help would be appreciated

Thanks

like image 693
Deep Singh Baweja Avatar asked Dec 10 '22 09:12

Deep Singh Baweja


1 Answers

The other easier way you are asking for:

You can just append .keyword to the field name you want to search text from. For eg: field name is identifier, so just use it as identifier.keyword

This will help you for sure.

like image 91
Ranvijay Jamwal Avatar answered May 21 '23 16:05

Ranvijay Jamwal