Unknown key for create index – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 7-8.9

Briefly, this error occurs when Elasticsearch encounters an unrecognized key in the settings or mappings during the index creation process. This could be due to a typo, incorrect syntax, or usage of a feature not supported in your Elasticsearch version. To resolve this, first, verify the keys used in your index creation request. Ensure they are correctly spelled and formatted. Second, check your Elasticsearch version and the compatibility of the features you’re trying to use. Lastly, ensure your JSON is correctly structured and valid.

<

Before you dig into reading this guide, have you tried asking OpsGPT what this log means? You’ll receive a customized analysis of your log.

Try OpsGPT now for step-by-step guidance and tailored insights into your Elasticsearch/OpenSearch operation.

p>To understand why this error arises when an index doesn’t have a defined key in the request body, you should run the AutoOps for Elasticsearch . It will help you resolve the issue and prevent it from occuring in the future.

This guide will help you check for common problems that cause the log “unknown key for create index” to appear. It’s important to understand the issues related to the log, so to get started, read the general overview on common issues and tips related to the Elasticsearch concepts: admin, indices and index.

Background

Each index created can have specific settings, mapping definitions and index aliases. The above error arises when the request body of the create index API is not correctly formed. 

Refer to this guide to learn more about various parameters and settings included under each section of the request body. For example – If the index setting (like analysis) is not defined under the request body’s settings section, then the below error will arise.

How to reproduce this exception

Create an index, with the below settings and mappings.

Index mapping:

PUT /my-index
{
 "settings": {
   "number_of_shards": 2,
   "number_of_replicas": 1
 },
 "analysis": {
   "analyzer": {
     "my_analyzer": {
       "type": "custom",
       "tokenizer": "standard",
       "filter": [
         "lowercase"
       ]
     }
   }
 },
 "mappings": {
   "properties": {
     "question": {
       "type": "text",
       "analyzer": "my_analyzer"
     }
   }
 }
}

The response will be:

{
 "error": {
   "root_cause": [
     {
       "type": "parse_exception",
       "reason": "unknown key [analysis] for create index"
     }
   ],
   "type": "parse_exception",
   "reason": "unknown key [analysis] for create index"
 },
 "status": 400
}

How to fix this exception

The analysis section needs to be located inside the top-level settings section.

Modify the index mapping:

PUT /my-index
{
 "settings": {
   "number_of_shards": 2,
   "number_of_replicas": 1,
   "analysis": {                      // note this
     "analyzer": {
       "my_analyzer": {
         "type": "custom",
         "tokenizer": "standard",
         "filter": [
           "lowercase"
         ]
       }
     }
   }
 },
 "mappings": {
   "properties": {
     "question": {
       "type": "text",
       "analyzer": "my_analyzer"
     }
   }
 }
}

Log Context

Log “unknown key [{}] for create index” class name is CreateIndexRequest.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 mapping(entry1.getKey(); (Map) entry1.getValue());
 }
 } else if (ALIASES.match(name; deprecationHandler)) {
 aliases((Map) entry.getValue());
 } else {
 throw new ElasticsearchParseException("unknown key [{}] for create index"; name);
 }
 }
 return this;
 }

 

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?