使用Java API更新ElasticSearch索引中的嵌套字段 [英] Update nested field in an index of ElasticSearch with Java API
问题描述
我有一个打字机是一个嵌套字段,我想更新此字段。
这是我的类型映射:
enduser :{
properties:{
location:{
type:nested,
properties:{
point type:geo_point}
}
}
}
}
当然,我的最终用户类型将有其他参数。
现在我想在我的嵌套字段中添加此文档:
location:{
name:London,
point:44.5,5.2
}
我正在搜索如何更新嵌套文档的文档,但找不到任何内容。例如,我有一个字符串以前的JSON对象(让我们来调用这个字符串json)。我尝试了以下代码,但似乎不起作用:
params.put(location,json);
client.prepareUpdate(index,ElasticSearchConstants.TYPE_END_USER,id).setScript(ctx._source.location = location)。setScriptParams(params).execute()。actionGet();
我从弹性搜索中得到一个解析错误。任何人都知道我做错了什么?
我试图重新创建你的情况,我用另一种方式解决了。 setScript方法。
您现在的更新请求如下所示:
client.prepareUpdate(index,ElasticSearchConstants.TYPE_END_USER,id).setScript(ctx._source.location =+ json).execute()。actionGet()
希望会帮助你。
I am using Java API for CRUD operation on elasticsearch.
I have an typewith a nested field and I want to update this field.
Here is my mapping for the type:
"enduser": {
"properties": {
"location": {
"type": "nested",
"properties":{
"point":{"type":"geo_point"}
}
}
}
}
Of course my enduser type will have other parameters.
Now I want to add this document in my nested field:
"location":{
"name": "London",
"point": "44.5, 5.2"
}
I was searching in documentation on how to update nested document but I couldn't find anything. For example I have in a string the previous JSON obect (let's call this string json). I tried the following code but seems to not working:
params.put("location", json);
client.prepareUpdate(index, ElasticSearchConstants.TYPE_END_USER,id).setScript("ctx._source.location = location").setScriptParams(params).execute().actionGet();
I have got a parsing error from elasticsearch. Anyone knows what I am doing wrong ?
I tried to recreate your situation and i solved it by using an other way the .setScript method.
Your updating request now would looks like :
client.prepareUpdate(index, ElasticSearchConstants.TYPE_END_USER,id).setScript("ctx._source.location =" + json).execute().actionGet()
Hope it will help you.
这篇关于使用Java API更新ElasticSearch索引中的嵌套字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!