Elasticsearch:使用无痛脚本获取对象索引 [英] Elasticsearch: Get object index with Painless script
本文介绍了Elasticsearch:使用无痛脚本获取对象索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个嵌套类型,我需要获取特定对象的索引才能执行更新:
I have a nested type and I need to get the index of a specific object to perform an update:
{
"_index": "asset_en_v1",
"_type": "note",
"_id": "23217",
"_version": 24,
"found": true,
"_source": {
"user_id": "11",
"title": "Title",
"note": "Note.",
"creation": "2017-05-31T21:36:01",
"modification": "2017-05-31T21:36:01",
"links": [
{
"note_link_id": "7310",
"user_id": "11",
"creation": "2017-06-01T14:41:50",
"modification": "2019-06-01T14:42:00",
"comment": "Comment goes here."
},
{
"note_link_id": "7311",
"user_id": "11",
"creation": "2017-06-01T14:42:42",
"modification": "2019-06-01T14:42:00",
"comment": "Yep..."
},
{
"note_link_id": "7312",
"user_id": "11",
"creation": "2017-06-01T15:33:55",
"modification": "2017-06-01T15:34:00",
"comment": "Jumo."
}
]
}
}
到目前为止,我已经在无痛脚本中创建了一个 _update
语句,该语句几乎完成了工作,但我一直在努力寻找匹配项:
So far, I've created an _update
statement in Painless script that almost does the job, but I'm struggling to get a match:
{
"script": {
"lang": "painless",
"inline": "def note_link_id = 7311; def links = ctx._source.links; for (int i = 0; i < links.length; ++i) { if (links[i].note_link_id == note_link_id) { ctx._source.links[note_link_id].comment = params.comment; ctx._source.links[note_link_id].modification = params.modification } }",
"params": {
"modification": "2019-06-01T14:42:00",
"comment": "QWERTY!"
}
}
}
在这里,链接[i].note_link_id== note_link_id
不匹配.
有什么想法吗?
推荐答案
在您的内联脚本中,它应该是i ++,而不是++ i
In your inline script, it should have been i++, instead of ++i
def note_link_id = 7311;
def links = ctx._source.links;
for (int i = 0; i < links.length; i++) //Note i++, instead of ++i
{
if (links[i].note_link_id == note_link_id)
{
ctx._source.links[note_link_id].comment = params.comment;
ctx._source.links[note_link_id].modification = params.modification
}
}
这篇关于Elasticsearch:使用无痛脚本获取对象索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文