Enable Elasticsearch field data for custom fields

Text fields are not optimized for operations that require field data per document, such as aggregations and sorts. These operations are therefore disabled by default. Please use a keyword field instead. Alternatively, you can set fielddata=true on [customFields.nameOfTheField] to load field data by not inverting the inverted index. Note that this can consume a significant amount of storage space.


Prerequisites:

  • cURL
  • IP address of the Elasticsearch server
  • The port used for API requests to Elasticsearch, if different from port 9200
  • An Elasticsearch user with "Monitor" or "Manage Index" permissions for the respective data stream, index, or alias
  • Name of the field for which field data is to be enabled


Relevant error message from your application

Field data is disabled on [customFields.nameDesFeldes] in [name_des_index_test1234abc1234def12341234]


Determine Existing Indexes

Before enabling field data for a text field, you must first determine whether the relevant index exists in your Elasticsearch instance.

To determine the existing indexes, use the following cURL command:

curl --user "<username>:<password>" -X GET "<IP address>:<ElasticsearchPort>/_cat/indices?pretty"


Sample output:

green open sw_xy_product_test1234abc1234def12341234 GRqwRVjfQ5qgCBPy-vRUQg 1 0  0   0   227b   227b


If the index you are looking for does not exist, you must first create it.



Determine the mapping for the custom field

After verifying that the index exists, you must determine the mapping for the relevant custom text field.

curl --user "<username>:<password>" -X GET "<IP address>:<ElasticsearchPort>/name_of_index_test1234abc1234def12341234/_mapping/field/custom*?pretty=true"


Sample output:

...
"customFields" : {
 "dynamic" : "true",
 "properties" : {
            "custom_test_set_numbers_" : {
 "type" : "double"
 },
 "custom_test_set_test_text" : {
 "type" : "long"
 }
 }
        },
...



Enable Field Data for Custom Fields

Once you have verified both the relevant index and the relevant custom field, you can set the field data to true using the following cURL command:

curl --user "<username>:<password>" -X PUT "<IP address>:<ElasticsearchPort>/name_of_index_test1234abc1234def12341234/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "customFields.core_assortment_dg": { 
      "type":     "text",
 "fielddata": true
    }
  }
}'


Next, verify your changes by checking the mapping for the custom field as described earlier.

If the customField has been correctly set to true, the Elasticsearch field data (Fielddata) for the custom field has been successfully enabled.


Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#fielddata-mapping-param