Routing values must be strings but found – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 8-8

Briefly, this error occurs when a non-string value is used for routing in Elasticsearch. Elasticsearch requires routing values to be strings, and using a different data type will result in this error. To resolve this issue, ensure that the routing value is a string. If the value is a number, it can be converted to a string before being used for routing. If the value is a complex object, consider using a unique identifier or a specific attribute of the object as the routing value instead.

This guide will help you check for common problems that cause the log ” Routing values must be strings but found [{}] ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: cluster, routing.

Log Context

Log “Routing values must be strings but found [{}]” class name is IndexRouting.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 if (source.currentToken() == Token.VALUE_STRING) {
 int hash = Murmur3HashFunction.hash(source.text());
 source.nextToken();
 return hash;
 }
 throw new ParsingException(source.getTokenLocation(); "Routing values must be strings but found [{}]"; source.currentToken());
 }  @Override
 public int updateShard(String id; @Nullable String routing) {
 throw new IllegalArgumentException(error("update"));

 

 [ratemypost]