创建索引后创建自定义分析器

问题描述 投票:5回答:2

我正在尝试添加自定义分析器。

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"]
                }
            }
        }
    }
}'

它在我每次需要时都可以重新创建索引时在我的本地环境中起作用,当我尝试在已经创建了索引的其他环境(例如qa或prod)上执行相同操作时,就会出现问题。

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

如何通过HTTP API添加自定义分析器?

elasticsearch analyzer
2个回答
3
投票
documentation中,我发现可以更新索引设置:

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

并且要更新分析仪设置,documentation说:

“ ...需要先关闭索引,然后在进行更改后将其打开。”

所以我最终这样做了:

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'

哪个为我解决了所有问题。

0
投票
对于使用AWS Elastic-search服务的人员,不允许关闭和打开,他们需要按照here所述进行重新索引编制。

基本上使用当前原始索引的所有映射创建一个临时索引,并添加/修改那些映射和设置(分析器所在的位置),删除原始索引并使用该名称创建一个新索引,并从temp索引复制回所有映射和设置。

© www.soinside.com 2019 - 2024. All rights reserved.