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

Sti*_*ine 18 elasticsearch

我想在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"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图添加这两行代码:

client.admin().indices().prepareUpdateSettings(Index).setSettings(settings).execute().actionGet();
client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();
Run Code Online (Sandbox Code Playgroud)

但这是结果:

org.elasticsearch.index.mapper.MapperParsingException: Analyzer [dot-analyzer] not found for field [location]
Run Code Online (Sandbox Code Playgroud)

任何人?非常感谢,

斯坦


这似乎有效:

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();
}
Run Code Online (Sandbox Code Playgroud)

jav*_*nna 33

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

curl -XPOST localhost:9200/index_name/_close
Run Code Online (Sandbox Code Playgroud)

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

curl -XPOST localhost:9200/index_name/_open
Run Code Online (Sandbox Code Playgroud)

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

client.admin().indices().prepareClose(indexName).execute().actionGet();
//TODO update settings
client.admin().indices().prepareOpen(indexName).execute().actionGet();
Run Code Online (Sandbox Code Playgroud)

  • 你的建议对我不起作用 - 关闭索引后,我得到IndexAlreadyExistsException.ElasticSearch 1.3.4 (3认同)