Creating a custom parser after creating an index

I am trying to add my own parser.

curl -XPUT 'http://localhost:9200/my_index' -d '{
    "settings" : {
        "analysis" : {
            "filter" : {
                "my_filter" : {
                    "type" : "word_delimiter",
                    "type_table": [": => ALPHA", "/ => ALPHA"]
                }
            },
            "analyzer" : {
                "my_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "whitespace",
                    "filter" : ["lowercase", "my_filter"]
                }
            }
        }
    }
}'

      

It works in my local environment where I can recreate the index every time I want, the problem comes when I try to do the same in other environments like qa or prod where the index is already created.

{
    "error": "IndexAlreadyExistsException[[my_index] already exists]",
    "status": 400
}

      

How do I add a custom parser via the HTTP API?

+3


source to share


1 answer


In the documentation, I found that to update the index settings, I can do this:

curl -XPUT 'localhost:9200/my_index/_settings' -d '
{
    "index" : {
        "number_of_replicas" : 4
    }
}'

      

And to update the parser settings, the documentation says:

"... you need to close the index first and open it after making changes."



So I ended up with this:

curl -XPOST 'http://localhost:9200/my_index/_close'

curl -XPUT 'http://localhost:9200/my_index' -d '{
    "settings" : {
        "analysis" : {
            "filter" : {
                "my_filter" : {
                    "type" : "word_delimiter",
                    "type_table": [": => ALPHA", "/ => ALPHA"]
                }
            },
            "analyzer" : {
                "my_analyzer" : {
                    "type" : "custom",
                    "tokenizer" : "whitespace",
                    "filter" : ["lowercase", "my_filter"]
                }
            }
        }
    }
}'

curl -XPOST 'http://localhost:9200/my_index/_open'

      

Which fixed everything for me.

+4


source







All Articles