Expected double array of length 2 – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-6.8

Briefly, this error occurs when Elasticsearch expects an array of two double values but doesn’t receive it. This is common when dealing with geo-point data types or other fields that require pairs of double values. To resolve this issue, ensure that the input data matches the expected format. For instance, if you’re dealing with geo-points, the input should be [longitude, latitude]. Also, check your mapping to ensure the field is correctly defined. Lastly, validate your data before indexing to avoid such errors.

This guide will help you check for common problems that cause the log ” Expected double array of length 2. ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: index, query.

Log Context

Log “Expected double array of length 2.” class name is GeoShapeQueryBuilder.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 if (queryShape instanceof GeoPoint) {
 pt = new double[] {((GeoPoint)queryShape).lon(); ((GeoPoint)queryShape).lat()};
 } else {
 pt = (double[])queryShape;
 if (pt.length != 2) {
 throw new QueryShardException(context; "Expected double array of length 2. "
 + "But found length " + pt.length + " for field [" + fieldName + "]");
 }
 }
 return LatLonShape.newBoxQuery(fieldName; relation.getLuceneRelation(); pt[1]; pt[1]; pt[0]; pt[0]);
 } else if (queryShape instanceof Object[]) {

 

 [ratemypost]