elasticsearch 新手遇到了小问题:
首先我创建了一个文档:
curl -XPOST http://localhost:9200/blog/article/ -d '{"title":"new version of Elasticsearch released!", "countent":"version 1.0 released today!", "tags":["announce","elasticsearch","release"]}'
然后返回:
{"_index":"blog","_type":"article","_id":"AV05vk4Jp9eqwTx-9EmQ","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}
这个是创建成功了的,然后我尝试使用 upsert 功能:
curl -XPOST http://localhost:9200/blog/article/AV05vk4Jp9eqwTx-9EmQ/_update -d '{"script":"ctx._source.count += 1", "upsert":{"count":0}}'
按照书上敲得,预期是将 count 字段加1,若是不存在,则插入 count 字段并设置为 0,但是报错了:
{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[neil-1][10.142.14.160:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"script_exception","reason":"runtime error","script_stack":["ctx._source.count += 1"," ^---- HERE"],"script":"ctx._source.count += 1","lang":"painless","caused_by":{"type":"null_pointer_exception","reason":null}}},"status":400}
求问这是什么原因
可能你看的是老版本,不同版本使用都不同,官网针对每个版本有教程