elasticsearch,

Fix 'illegal_argument_exception at shard' Elasticsearch error

Oct 04, 2022 · 2 mins read · Post a comment

Playing around with an existing ES cluster, I stumbled upon the following issue:

Type
illegal_argument_exception
Reason
Field [...] of type [text] does not support custom formats

Here I’m gonna share my thoughts and how I’ve managed to resolve it.

Prerequisites

  • Elasticsearch cluster
  • Opensearch cluster

Solution

Step 1. The first thing you need to make sure of is that you have enough memory and CPU dedicated for the cluster.

Step 2. Once that is sorted, you need to list all the shards and check the reason why they are unassigned.

GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state

Output:

index         shard   prirep   state           node      unassigned.reason
index1        2       r      UNASSIGNED       907584     INDEX_CREATED
index2        3       r      UNASSIGNED       907584     INDEX_CREATED

Step 3. There is another cool command for checking the failure reason.

GET _cluster/allocation/explain

The explanation row is pretty much self-explanatory so you can figure out what’s the root issue of the unassigned shards and fix it depending on the message.

Step 4. Nonetheless, the tricky part comes when all of these commands might not be useful regarding the description error.

illegal_argument_exception at shard 0 index index1 node node1
Type
illegal_argument_exception
Reason
Field [...] of type [text] does not support custom formats

The thing is the first line of the error tells you that the issue is connected with a specific shard on a specific index. So in my case, it turned out that the mapping of that particular index was different from the other ones. The Reason section will tell you which field and type is the wrong one in the mapping of the index.

  • One approach is to change the mapping of that particular index field type. If the error above says [text] does not support custom formats then you need to know the right type for that field. For example date field cannot contain type text. It should be a date type.
    PUT /index1/_mapping
    {
    "properties": {
      "date": {
        "type": "date"
      }
    }
    }
    
  • As a last option, you can try to delete and re-create that particular index. Please keep in mind that you will lose the index data if you don’t create a snapshot or backup of it.

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.