Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Single analyzer across multiple index

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?

like image 314
Kaushik J Avatar asked Dec 21 '25 18:12

Kaushik J


1 Answers

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"
                }
            }
        }
    }
}
like image 134
Amit Avatar answered Dec 24 '25 12:12

Amit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!