我希望在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]
有没有人?非常感谢,
Stine
这似乎起作用了:
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();
}
发布于 2012-09-11 19:11:08
如果您在发送更改后查看您的设置,您会注意到分析器不在那里。事实上,您不能更改实时索引上设置的分析部分。最好使用所需的设置创建它,否则您可以直接将其关闭:
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();
https://stackoverflow.com/questions/12367877
复制相似问题