3

I have time-based indices

students-2018

students-2019

students-2020

I have defined 1 analyzer with synonyms, I want to reuse the same analyzer across multiple indexes, how do I achieve that?

1
  • @OpsterElasticsearchNinja your solution worked for newly created indices, but it didn't reflect changes for existing indices (please help) Commented May 8, 2020 at 17:36

1 Answer 1

3

You can define an index template and then create your custom analyzer with that template which includes all your student indices.

You can add your index-pattern in below index template call as mention in the official doc.

Sample index template def

{
    "index_patterns": ["student-*"],
    "settings": {
        "analysis": {
            "analyzer": {
                "my_custom_analyzer": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "char_filter": [
                        "html_strip"
                    ],
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
    }
}

Now all your student indices like students-2018 , students-2019 will have this my_custom_analyzer which is defined in the index template.

Create a student index without any setting and analyzer like

http://{{you-es-hostname}}/student-2018

And then check its setting using GET http://{{you-es-hostname}}/student-2018, which would give below output and includes the analyzer created in the index template.

{
    "student-2018": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "number_of_shards": "5",
                "provided_name": "student-2018",
                "creation_date": "1588653678067",
                "analysis": {
                    "analyzer": {
                        "my_custom_analyzer": {
                            "filter": [
                                "lowercase",
                                "asciifolding"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "standard"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "kjGEgKCOSJeIlrASP-RaMQ",
                "version": {
                    "created": "7040299"
                }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

template should be index_patterns instead
@Val, its more of a best practice, works without it as well. would ass it as well, Thanks
All I meant is that to be future-proof (i.e. for people coming to this question in the future), it might be better not to use things we already know are deprecated. It's not a "best practice", it's a deprecated field name since ES 6.0. Thanks for updating it.
@Val, ahh, didn't know its deprecated, thanks for correcting me , your are welcome always :)
@KaushikJ, yeah it would not work for existing index and template is used when you create a index using the template, so it wouldn't include the existing index. you need to create a create a new index , you can use the reindex API elastic.co/guide/en/elasticsearch/reference/current/…
|

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.