elasticsearch upsert 问题

查看:253
本文介绍了elasticsearch upsert 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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}

求问这是什么原因

解决方案

可能你看的是老版本,不同版本使用都不同,官网针对每个版本有教程

这篇关于elasticsearch upsert 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆