pan*_*los 5 java elasticsearch jest
我正在尝试使用特定的分析器和映射在ES中创建索引,使用JEST.我使用以下代码:
CreateIndex createIndex = new CreateIndex.Builder(indexName)
.settings(
ImmutableSettings.builder()
.loadFromClasspath(
"jestconfiguration.json"
).build().getAsMap()
).build();
JestResult result = client.execute(createIndex);
Run Code Online (Sandbox Code Playgroud)
这是jestconfiguration.java
{
"settings": {
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym"
]
}
},
"filter": {
"synonym" : {
"type" : "synonym",
"synonyms" : [
"smart phone => smartphone"
]
}
}
}
},
"mappings": {
"index_type": {
"properties": {
"Name": {
"type": "string",
"analyzer": "second"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然索引使用指定的"设置"正确装箱,但"映射"部分不起作用,我无法设置字段"名称"的映射.有人有想法吗?putmapping()
JESt中是否有一种可以添加映射的东西?理想情况下,我希望能够动态设置field_name而不是.json文件.
Thnks
我在尝试查看是否可以一次性创建索引和映射时发现了您的问题。我最终只是创建了第二个创建映射的请求。
String mappingJson = new String(ByteStreams.toByteArray(mappingFile.getInputStream()));
boolean indexExists = client.execute(new IndicesExists.Builder(configuration.getIndex()).build()).isSucceeded();
if (indexExists) {
logger.info("Updating elasticsearch type mapping.");
client.execute(new PutMapping.Builder(configuration.getIndex(), configuration.getBaseType(), mappingJson).build());
} else {
logger.info("Creating elasticsearch index and type mapping.");
client.execute(new CreateIndex.Builder(configuration.getIndex()).build());
client.execute(new PutMapping.Builder(configuration.getIndex(), configuration.getBaseType(), mappingJson).build());
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2662 次 |
最近记录: |