通过查询查找并在弹性搜索中推送到数组

时间:2018-03-10 05:16:42

标签: elasticsearch

我将数据存储在弹性搜索中,如下所示:

{
"_index": "my_index",
"_type": "doc",
"_id": "6lDquGEBFRQVe0x93eHk",
"_version": 1,
"_score": 1,
"_source": {
"ID_Number": "6947503728601",
"Userrname":"Jack.m07",
"name": "Jack",
"photos": ["img/one.png"]
}
}

我希望按ID_Number查找用户并将新值推送到Photos

e.g)

"photos": ["img/one.png","img/two.png"]

我该如何实现?什么是查询?

1 个答案:

答案 0 :(得分:0)

我找到了答案,这是查询

POST my_index/_update_by_query?conflicts=proceed
{
  "script": {
    "inline": "ctx._source.photos.add(params.new_photos)",
    "params": {
      "new_photos": "img/two.png"
    }
  },
  "query": {
    "terms": {
      "ID_Number": "6947503728601"
    }
  }
}