0

I have created custom analyzer for Elasticsearch and it's working as expected, however I'm not able to set it as default one for index. I'm only able to set it for each field separately, but it's important for me to have it as default, since index mapping will probably change overtime and I'd like to avoid having to remember to set analyzer for each new field.

Json contents I'm using for index creation:

{
    "settings": {
        "analysis": {
            "char_filter": {
                "my_mappings_char_filter": {
                    "type": "mapping",
                    "mappings": [
                        "- => ¡h¡",
                    ],
                }
            },
            "analyzer": {
                "test_analyzer": {
                    "tokenizer": "whitespace",
                    "char_filter": ["my_mappings_char_filter"],
                    "filter": ["lowercase"]
                },
                "default": {
                    "type": "test_analyzer"
                }
            },
        }
    },
}

Response is below (status 400)

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Unknown analyzer type [test_analyzer] for [default]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Unknown analyzer type [test_analyzer] for [default]"
  },
  "status": 400
}

I'm following those instructions from official elastic docs, but for some reason it throws error in my case? Or maybe it's not possible to have custom analyzer as default?

1 Answer 1

1

The default analyzer setting is not a reference to an existing analyzer (except built-in ones) but a full-blown definition of its own. This will work:

{
  "settings": {
    "analysis": {
      "char_filter": {
        "my_mappings_char_filter": {
          "type": "mapping",
          "mappings": [
            "- => ¡h¡"
          ]
        }
      },
      "analyzer": {
        "default": {
          "type": "custom",
          "tokenizer": "whitespace",
          "char_filter": [
            "my_mappings_char_filter"
          ],
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.