我有一个批量运行的upsert查询。最终文件将如下存储:
{
"email": "abc@xyz.com",
"sources": [1,2]
}
以下是代码:
var doc = {
"source": parseInt(id),
"email": email
}
var upsert_query = {
"script": "if (ctx._source.containsKey(\"sources\")) { if (!ctx._source.sources.contains(source)) { ctx._source.sources += source; } } else {ctx._source.sources = [source] }",
"params": {
"source": doc.source
},
"upsert": {
"email": doc.email,
"sources": [doc.source]
}
}
bulkRequestBody.push({"update": {"_index": "my_index", "_type": "email", "_id": doc.email, "_retry_on_conflict": 3}});
bulkRequestBody.push(upsert_query);
代码在elasticsearch 1.4版上完全正常,但在2.1.1版本上无效。
我还试图重构我的查询:
var upsert_query = {
"script": {
"inline": "if (ctx._source.containsKey(\"sources\")) { if (!ctx._source.sources.contains(source)) { ctx._source.sources += source; } } else {ctx._source.sources = [source] }",
"params": {
"source": doc.source
}
},
"upsert": {
"email": doc.email,
"sources": [doc.source]
}
}
但仍然没有运气。有什么帮助吗?
答案 0 :(得分:0)
需要启用脚本来运行这样的脚本:
在config中的elasticsearch.yml
文件中,添加以下行:
script.inline: on
script.indexed: on