Activate Elasticsearch field data (Fielddata) for custom fields

Text fields are not optimized for operations that require field data per document, such as aggregations and sorting. These operations are therefore disabled by default. Please use a keyword field instead. Alternatively, you can set fielddata=true to [customFields.nameDesFeldes] to load field data by not inverting the inverted index. Please note that this can take up considerable memory space.


Prerequisites:

  • cURL
  • IP address of the Elasticsearch server
  • If different from port 9200, API requests to Elasticsearch concerning the port
  • Elasticsearch user with "Monitor" or "Manage Index" authorization for the respective data stream, index or alias
  • Name of the field for which field data is to be activated


Relevant error message from your application

Fielddata is disabled on [customFields.nameDesFields] in [name_des_index_test1234abc1234def12341234]


Determine existing indexes

Before activating the field data for a text field, you must first determine whether the index in question 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"


Output example:

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


If the index you are looking for does not exist, the corresponding index must first be created.



Determine mapping for the custom field

Once you have verified that the index exists, the mapping for the relevant custom field text field must be determined.

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


Output example:

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



Activate field data for custom field

If you have verified the relevant index and the relevant custom field, you can set the field data to true with 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
    }
  }
}'


Then verify your changes by checking the mapping for the custom field as described above.

If the customField has been correctly adjusted to true, the Elasticsearch field data (Fielddata) for Custom Field has been successfully activated.


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