更改 Elasticsearch 中现有索引的设置和映射 [英] Change settings and mappings on existing index in Elasticsearch

查看:26
本文介绍了更改 Elasticsearch 中现有索引的设置和映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 Elasticsearch 中的现有索引上设置以下设置和映射:

I would like the following settings and mapping set on an already existing index in Elasticsearch:

{
    "analysis": {
        "analyzer": {
            "dot-analyzer": {
                "type": "custom",
                "tokenizer": "dot-tokenizer"
            }
        },
        "tokenizer": {
            "dot-tokenizer": {
                "type": "path_hierarchy",
                "delimiter": "."
            }
        }
    }
}

{
    "doc": {
        "properties": {
            "location": {
                "type": "string",
                "index_analyzer": "dot-analyzer",
                "search_analyzer": "keyword"
            }
        }
    }
}

我已经尝试添加这两行代码:

I have tried to add these two lines of code:

client.admin().indices().prepareUpdateSettings(Index).setSettings(settings).execute().actionGet();
client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();

但这就是结果:

org.elasticsearch.index.mapper.MapperParsingException: Analyzer [dot-analyzer] not found for field [location]

有人吗?非常感谢,

斯汀

这似乎有效:

if (client.admin().indices().prepareExists(Index).execute().actionGet().exists()) {            
    client.admin().indices().prepareClose(Index).execute().actionGet();
    client.admin().indices().prepareUpdateSettings(Index).setSettings(settings.string()).execute().actionGet();
    client.admin().indices().prepareOpen(Index).execute().actionGet();
    client.admin().indices().prepareDeleteMapping(Index).setType(Type).execute().actionGet();
    client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();
} else {
    client.admin().indices().prepareCreate(Index).addMapping(Type, mapping).setSettings(settings).execute().actionGet();
}

推荐答案

如果您在发送更改后查看您的设置,您会注意到分析器不在那里.事实上,您无法更改实时索引设置的分析部分.最好使用所需的设置创建它,否则您可以关闭它:

If you look at your settings after sending the changes you'll notice that the analyzer is not there. In fact you can't change the analysis section of the settings on a live index. Better to create it with the desired settings, otherwise you can just close it:

curl -XPOST localhost:9200/index_name/_close

当索引关闭时,您可以发送新设置.之后,您可以重新打开索引:

While the index is closed you can send the new settings. After that you can reopen the index:

curl -XPOST localhost:9200/index_name/_open

当索引关闭时,它不使用任何集群资源,但它不可读也不可写.如果要使用 Java API 关闭并重新打开索引,可以使用以下代码:

While the index is closed it doesn't use any cluster resource, but it is not readable nor writable. If you want to close and reopen the index using the Java API you can use the following code:

client.admin().indices().prepareClose(indexName).execute().actionGet();
//TODO update settings
client.admin().indices().prepareOpen(indexName).execute().actionGet();

这篇关于更改 Elasticsearch 中现有索引的设置和映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆