Property value on field n must be a number or a string but got o – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 7.16-8.9

Briefly, this error occurs when the data type of the value assigned to a field in Elasticsearch is neither a number nor a string. Elasticsearch expects data types to be consistent with the mapping defined for the index. To resolve this, ensure that the data type of the value matches the field’s mapping. If the mapping is not defined, Elasticsearch will try to infer the data type based on the first document indexed. You can also explicitly define the mapping for the field to avoid such issues.

This guide will help you check for common problems that cause the log ” Property [value] on field [” + n + “] must be a number or a string; but got [” + o + “] ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: plugin.

Log Context

Log “Property [value] on field [” + n + “] must be a number or a string; but got [” + o + “]” class name is ConstantKeywordFieldMapper.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 // This is defined as updateable because it can be updated once; from [null] to any value;
 // by a dynamic mapping update. Once it has been set; however; the value cannot be changed.
 private final Parameter value = new Parameter<>("value"; true; () -> null; (n; c; o) -> {
 if (o instanceof Number == false && o instanceof CharSequence == false) {
 throw new MapperParsingException("Property [value] on field [" + n + "] must be a number or a string; but got [" + o + "]");
 }
 return o.toString();
 }; m -> toType(m).fieldType().value; XContentBuilder::field; Objects::toString);
 private final Parameter> meta = Parameter.metaParam();

 

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?