我想在弹性搜索中使用“tags”:[“red”]
向数组JavaScript api
添加内容,目前,我按照以下方式执行此操作:
client.update(
"test":{
"index": "test",
"type": "type1",
"id": "1",
"body": {
"script": "ctx._source.tags += tag",
"params": { "tag": "blue" }
}
})
这会将字段"tags" : ["red"]
更改为"tags" : blue
而不是["red","blue"]
,
我使用curl -XPUT or curl -XPOST
方法
我的节点模块弹性搜索版本为2.4.2
弹性搜索服务器为1.3.2
请帮助......
答案 0 :(得分:2)
ElasticSearch脚本引擎不支持支持javascript,请阅读:why not javascript。
要将项目添加到array
,请使用add()
功能,而不是+=
curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{
"script":"ctx._source.tags.add(tag)",
"params":{"tag":"blue"}
}'