沙师弟,师父的充电器掉了

elastic search 如何向list字段里面追加数据

Elasticsearch | 作者 wangmeng | 发布于2019年10月12日 | 阅读数:2721

self._es.update(
index=u'company',
id=company_row[u'id'],
body={"script" : "ctx._source.test+= newElement",
"params": {
"newElement": {
"key": XXX,
"value": XXXX}}})
已邀请:

stone_xy

赞同来自: wangmeng

POST test/_doc
{
"f1": ["d1"]
}


POST test/_doc/_update_by_query?pretty
{
"script": {
"inline": "ctx._source.f1.add(params.hits)",
"params": {
"hits": "d2"
}
},
"query": {
"match_all": {}
}
}

GET test/_search
结果如下:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "QqS9vW0BtZvIlit_tjnm",
"_score": 1,
"_source": {
"f1": [
"d1",
"d2"
]
}
}
]
}
}

要回复问题请先登录注册