使用java api配置弹性搜索映射 [英] Configure elasticsearch mapping with java api
本文介绍了使用java api配置弹性搜索映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些弹性搜索字段,我不想在索引之前进行分析。我已经看到正确的方法是通过改变索引映射。现在我的映射如下所示:
I have a few elasticsearch fields that I don't want to analyze before indexing. I have read that the right way to do this is by altering the index mapping. Right now my mapping looks like this:
{
"test" : {
"general" : {
"properties" : {
"message" : {
"type" : "string"
},
"source" : {
"type" : "string"
}
}
}
}
}
我希望看起来像这样:
{
"test" : {
"general" : {
"properties" : {
"message" : {
"type" : "string",
"index" : "not_analyzed"
},
"source" : {
"type" : "string"
}
}
}
}
}
我一直在尝试通过
client.admin().indices().prepareCreate("test")
.setSettings(getGrantSettings());
getGrantSettings()看起来像:
Where getGrantSettings() looks like:
static Settings getGrantSettings(){
JSONObject settingSource = new JSONObject();
try{
settingSource.put("mapping", new JSONObject()
.put("message", new JSONObject()
.put("type", "string")
.put("index", "not_analyzed")
));
} catch (JSONException e){
e.printStackTrace();
}
Settings set = ImmutableSettings.settingsBuilder()
.loadFromSource(settingSource.toString()).build();
return set;
}
推荐答案
我已成功应用映射使用Java API的Elasticsearch索引,如下所示:
I have successfully applied mappings to an Elasticsearch index using the Java API like the following:
XContentBuilder mapping = jsonBuilder()
.startObject()
.startObject("general")
.startObject("properties")
.startObject("message")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.startObject("source")
.field("type","string")
.endObject()
.endObject()
.endObject()
.endObject();
PutMappingResponse putMappingResponse = client.admin().indices()
.preparePutMapping("test")
.setType("general")
.setSource(mapping)
.execute().actionGet();
希望这有帮助。
这篇关于使用java api配置弹性搜索映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文