Text fields are not optimised for operations that require per-document field data like aggregations and sorting

Created on 19 October 2022, about 2 years ago
Updated 13 March 2024, 9 months ago

I use

Wodby docker image,
php 8.1.7,
Drupal core 9.4.8,
Search API 8.x-1.24,
Search API Autocomplete 8.x-1.6,
Elasticsearch Connector Autocomplete 8.x-1.2.
Elasticsearch Connector dev-8.0.x version with 9 contrib patches

The autocomplete search failed with this error message:

Failed to make search call to http://elastic:9200/xxxx_field_name/_search.
Elasticsearch response: Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [field_name] in order to load field data by uninverting the inverted index. Note that this can use significant memory. [reason: all shards failed]

Steps to reproduce

  • Create fulltext fields in search api ui in /admin/config/search/search-api/index/index_name/fields
  • Configure suggester Retrieve from server select one field in /admin/config/search/search-api/index/index_name/autocomplete/index_name/edit
  • Prepare views add above field to filter section and expose it
  • Go to views page and type in above field

After page reload will see the erreor message because ajax.
I do not find a place where can fielddata=true setting also where can define keyword tag for fields.
I prepared a fix which is working me. Please review it.

🐛 Bug report
Status

Postponed: needs info

Version

8.0

Component

Code

Created by

🇭🇺Hungary dj1999

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada mparker17 UTC-4

    In 📌 Investigate search_api_opensearch as base for elasticsearch_connector Fixed , we made a bunch of changes to how the 8.0.x version of this module works. I manually tested it with Search API Autocomplete and didn't receive any errors like this.

    May we trouble you to try out the latest 8.0.x-dev release and see if it meets your needs? If it does not, may we trouble you to change this issue's "Status" back to "Needs work"?

    (I'm cleaning up issues in the 8.0.x-dev branch as part of a big review of open issues for 🌱 Plan for 8.0.0-alpha release Active : thank you for your patience with me!)

  • 🇮🇳India mikebhatti

    I use

    Elasticsearch Connector: 8.x-7.0-alpha4
    Drupal 10.2.3

    The search page is returning this error:

    Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"elasticsearch_index_ccsa_index","node":"anDpZ9_cTWyXZt6Y_yu7fw","reason":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory.","caused_by":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}},"status":400} in Elasticsearch\Connections\Connection->process4xxError() (line 693 of /srv/ccsa-website-drupal/src/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php).

    I tried the patch given above but still getting the same error.

  • 🇮🇳India mikebhatti

    I'm getting this error on search page. I'm using Drupal 10.2.3 and Elasticsearch Connector 8.x-7.0-alpha4.

    Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"elasticsearch_index_ccsa_index","node":"anDpZ9_cTWyXZt6Y_yu7fw","reason":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory.","caused_by":{"type":"illegal_argument_exception","reason":"Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [type] in order to load field data by uninverting the inverted index. Note that this can use significant memory."}}},"status":400} in Elasticsearch\Connections\Connection->process4xxError() (line 693 of /srv/ccsa-website-drupal/src/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php).

    I tried the patch above but it doesn't work.

  • Status changed to Active 9 months ago
  • 🇨🇦Canada mparker17 UTC-4

    I'll change the ticket to Version 8.x-7.x-dev, and Status back to Active.

  • 🇮🇳India keshavv India

    I am getting the same error today on Drupal 10.2.6 and not able to resolve it.

  • 🇧🇪Belgium robindh

    I encountered a very similar issue, but with elasticsearch connector 8.x-7.0-alpha4. This actual problem was my mapping not being imported.

    When navigating to /admin/config/search/search-api/index/myindex/fields and saving the form, I noticed this error:
    Failed to parse mapping [_doc]: unknown parameter [fielddata] on mapper [myfield] of type [keyword]

    At this point my index mapping is basically empty. When executing a query the response is:
    Text fields are not optimised for operations that require per-document field data like aggregations and sorting ...

    Presumably, this happens because elasticsearch doesn't map text fields as fielddata by default.
    Fixed it by only adding fielddata mapping to text fields, since other fields don't support it.

    Attaching a patch for version 8.x-7.0-alpha4

Production build 0.71.5 2024