首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Elasticsearch中更改现有索引的设置和映射

在Elasticsearch中更改现有索引的设置和映射
EN

Stack Overflow用户
提问于 2012-09-11 18:40:08
回答 1查看 18K关注 0票数 20

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

代码语言:javascript
复制
{
    "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"
            }
        }
    }
}

我尝试添加以下两行代码:

代码语言:javascript
复制
client.admin().indices().prepareUpdateSettings(Index).setSettings(settings).execute().actionGet();
client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();

但这就是结果:

代码语言:javascript
复制
org.elasticsearch.index.mapper.MapperParsingException: Analyzer [dot-analyzer] not found for field [location]

有没有人?非常感谢,

Stine

这似乎起作用了:

代码语言:javascript
复制
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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-11 19:11:08

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

代码语言:javascript
复制
curl -XPOST localhost:9200/index_name/_close

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

代码语言:javascript
复制
curl -XPOST localhost:9200/index_name/_open

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

代码语言:javascript
复制
client.admin().indices().prepareClose(indexName).execute().actionGet();
//TODO update settings
client.admin().indices().prepareOpen(indexName).execute().actionGet();
票数 36
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12367877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档