0
votes

I want to sort elasticsearch result documents with icu_collation filter. So I have settings for index:

"settings": {
    "analysis": {
      "analyzer": {
        "ducet_sort": {
          "tokenizer": "keyword",
          "filter": [ "icu_collation" ]
        }
      }
    }
  }

and mappings

"mappings": {
    "card": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "sort": {
              "type": "text",
              "analyzer": "ducet_sort",
              "index": false
            }
          }
        }
}}}

and query:

{
      "sort": ["title.sort"]
}

But query failed:

"caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [title.sort] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
        }

In documentation the suggested data type for sorting is keyword. But data type keyword doesn't support analyzer. In addition the fielddata is not recommended:

documentation

So is there a way for sorting documents in elasticsearch with some specific collation e.g. icu_collation without fielddata=true?

Thank you.

1
Before you enable fielddata, consider why you are using a text field for aggregations, sorting, or in a script. It usually doesn’t make sense to do it. So, why you need it? - Mysterion
I need sorting by icu_collation. How can I do it with different data type e.g. keyword? - limuhob
they just propose to enable fielddata elastic.co/guide/en/elasticsearch/plugins/current/… - Mysterion

1 Answers

0
votes

In Kibana, open Dev Tools option from left menu and execute the query below after update according to your settings.

PUT _mapping/INDEX_NAME?update_all_types
{
  "properties": {
    "FIELD_NAME": {
      "type":     "text",
      "fielddata": true
    }
  }
}

or through Curl or a terminal like Cygwin(for Windows) execute the query below after update according to your settings.

curl -XPUT http://DOCKER_MACHINE_IP:9200/INDEX_NAME -d '{
  "mappings": {
    "type": {
      "properties": {
        "FIELD_NAME": {
          "type": "text",
          "fielddata": true
        }
      }
    }
  }
}'