Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch :: Exception while ceating index and document

I am new to ElasticSearch & was trying to execute the example mentioned in their home page where I came across this erorr -

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
        "suppressed": [
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.experience.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            },
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.name.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            },
            {
                "type": "illegal_argument_exception",
                "reason": "unknown setting [index.mappings.employee.properties.name.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
            }
        ]
    },
    "status": 400
}

The url & body of the post request are as follows -

URL - > http://localhost:9200/company BODY - >

{
  "settings": {
    "index": {
       "number_of_shards": 1,
       "number_of_replicas": 1
    },
    "analysis": {
      "analyzer": {
        "analyzer-name": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      }
    },
    "mappings": {
      "employee": {
        "properties": {
          "age": {
            "type": "long"
          },
          "experience": {
            "type": "long"      
          },
          "name": {
            "type": "string",
            "analyzer": "analyzer-name"
          }
        }
      }
    }
  }  
}

How to fix the error ?

like image 937
Deb Avatar asked Aug 24 '18 09:08

Deb


1 Answers

There are two errors in syntax of your JSON body object:

  1. Node settings must have only two childs: index and analysis. Node mappings must be root-level.
  2. Field name has invalid type string, it must be text or keyword. Because you need this field to be analyzed, it should be text in your case.

So working query for ES version 6.x (that was current at the time of the question) should be like this:

{
  "settings": {
    "index": {
       "number_of_shards": 1,
       "number_of_replicas": 1
    },
    "analysis": {
      "analyzer": {
        "analyzer-name": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      }
    }
  },
  "mappings": {
    "employee": {
      "properties": {
        "age": {
          "type": "long"
        },
        "experience": {
          "type": "long"      
        },
        "name": {
          "type": "text",
          "analyzer": "analyzer-name"
        }
      }
    }
  }
}

Starting from ES version 7.0, mapping types was removed from index definition, so the query above wouldn't work in ES 7.x.

Working query for ES version 7.x could be two types:

  1. If index should contain data only about employees, you can simply delete employee mapping type and query would be like this:

    {
      "settings": {
        "index": {
          "number_of_shards": 1,
          "number_of_replicas": 1
        },
        "analysis": {
          "analyzer": {
            "analyzer-name": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": "lowercase"
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "age": {
            "type": "long"
          },
          "experience": {
            "type": "long"      
          },
          "name": {
            "type": "text",
            "analyzer": "analyzer-name"
          }
        }
      }
    }
    
  2. If index should contain data about employees and some other data, you can use employee as field of the object type and query would be like this:

    {
      "settings": {
        "index": {
          "number_of_shards": 1,
          "number_of_replicas": 1
        },
        "analysis": {
          "analyzer": {
            "analyzer-name": {
              "type": "custom",
              "tokenizer": "keyword",
              "filter": "lowercase"
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "employee": {
            "properties": {
              "age": {
                "type": "long"
              },
              "experience": {
                "type": "long"      
              },
              "name": {
                "type": "text",
                "analyzer": "analyzer-name"
              }
            }
          }
        }
      }
    }
    
like image 56
Alexey Prudnikov Avatar answered Oct 30 '22 17:10

Alexey Prudnikov