【问题标题】:Change settings and mappings on existing index in Elasticsearch更改 Elasticsearch 中现有索引的设置和映射
【发布时间】:2012-09-04 06:36:21
【问题描述】:

我想在 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"
            }
        }
    }
}

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

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();
}

【问题讨论】:

标签: elasticsearch


【解决方案1】:

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

curl -XPOST localhost:9200/index_name/_close

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

curl -XPOST localhost:9200/index_name/_open

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

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

【讨论】:

  • 您的建议对我不起作用 - 关闭索引后,我得到 IndexAlreadyExistsException。弹性搜索 1.3.4
  • @javanna 当你重新打开索引时,会发生什么? ES 是否需要重新索引所有内容,因为您有一个新的分析器?
  • @javanna 我使用的是 elasticsearch 2.4 版,我得到了错误 - 索引已经存在 即使在关闭索引之后。您还有什么其他建议吗?
猜你喜欢
  • 2019-04-16
  • 1970-01-01
  • 2017-03-11
  • 2020-11-24
  • 2021-03-23
  • 1970-01-01
  • 2017-10-08
  • 1970-01-01
  • 2016-01-12
相关资源
最近更新 更多