使用javascript api弹性搜索插入数组

时间:2014-10-06 12:50:12

标签: javascript node.js elasticsearch

我想在弹性搜索中使用“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方法

通过Ubuntu终端获得预期输出

我的节点模块弹性搜索版本为2.4.2弹性搜索服务器为1.3.2

请帮助......

1 个答案:

答案 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"}
}'