Home > Enterprise >  illegal_argument_exception error elasticsearch
illegal_argument_exception error elasticsearch

Time:03-24

Below is my mapping for which I am trying to create an index in my elastic instance. I am creating an analyzer and tokenizer to analyze a url. I am using a custom elasticsearch analyzer which is already installed in my elasticsearch instance. My elasticsearch version is 5.6.16.

curl -X PUT localhost:9200/example-test?pretty -H 'Content-Type: application/json' -d'{
    "settings": {
        "analysis": {
            "filter": {
                "url_host": {
                    "type": "url",
                    "part": [
                        "protocol",
                        "whole",
                        "host",
                        "port",
                        "path",
                        "query",
                        "ref"
                    ],
                    "url_decode": true,
                    "allow_malformed": true,
                    "passthrough": true,
                    "tokenize_malformed": true
                }
            },
            "analyzer": {
                "url_host": {
                    "filter": [
                        "url_host",
                        "lowercase"
                    ],
                    "tokenizer": "split_on_non_word"
                }
            },
            "tokenizer": {
                "split_on_non_word": {
                    "type": "pattern",
                    "pattern": "\\W "
                }
            }
        },
        "mappings": {
            "example_type": {
                "properties": {
                    "url": {
                        "type": "text",
                        "fields": {
                            "url": {
                                "type": "string"
                            },
                            "host": {
                                "type": "string",
                                "analyzer": "url_host"
                            }
                        }
                    }
                }
            }
        }
    }
}'

But when I tried to create it, I am getting the below error.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "unknown setting [index.mappings.example_type.properties.url.fields.host.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.example_type.properties.url.fields.host.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
  },
  "status" : 400
}

CodePudding user response:

The mappings section should be a sibling of the settings section. This will work:

curl -X PUT localhost:9200/example-test?pretty -H 'Content-Type: application/json' -d'{
  "settings": {
    "analysis": {
      "filter": {
        "url_host": {
          "type": "url",
          "part": [
            "protocol",
            "whole",
            "host",
            "port",
            "path",
            "query",
            "ref"
          ],
          "url_decode": true,
          "allow_malformed": true,
          "passthrough": true,
          "tokenize_malformed": true
        }
      },
      "analyzer": {
        "url_host": {
          "filter": [
            "url_host",
            "lowercase"
          ],
          "tokenizer": "split_on_non_word"
        }
      },
      "tokenizer": {
        "split_on_non_word": {
          "type": "pattern",
          "pattern": ""
        }
      }
    }
  },
  "mappings": {
    "example_type": {
      "properties": {
        "url": {
          "type": "text",
          "fields": {
            "url": {
              "type": "string"
            },
            "host": {
              "type": "string",
              "analyzer": "url_host"
            }
          }
        }
      }
    }
  }
}'
  • Related