Cannot define script on field with index false and doc values false – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 7.13-8.9

Briefly, this error occurs when you try to define a script on a field that is not indexed and does not have doc_values enabled. Elasticsearch requires fields to be indexed or have doc_values enabled to perform operations like sorting, aggregating, or scripting. To resolve this issue, you can either set “index: true” to make the field searchable or set “doc_values: true” to enable on-disk column-oriented storage, which is useful for sorting and aggregations. Please note that changing these settings requires reindexing your data.

This guide will help you check for common problems that cause the log ” Cannot define script on field with index:false and doc_values:false ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: index.

Log Context

Log “Cannot define script on field with index:false and doc_values:false” class name is We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 Parameter indexParam;
 Parameter docValuesParam
 ) {
 scriptParam.addValidator(s -> {
 if (s != null && indexParam.get() == false && docValuesParam.get() == false) {
 throw new MapperParsingException("Cannot define script on field with index:false and doc_values:false");
 if (s != null && multiFieldsBuilder.hasMultiFields()) {
 throw new MapperParsingException("Cannot define multifields on a field with a script");
 if (s != null && copyTo.hasValues()) {


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?