Es更新给出了错误的请求

时间:2015-12-18 07:36:18

标签: elasticsearch

我正在尝试更新以下文档:

$ curl http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD?pretty
{
  "_index" : "customer",
  "_type" : "customer",
  "_id" : "AVGbTCQ2XioLLLZULBAD",
  "_version" : 15,
  "found" : true,
  "_source":{"age":0,"n":"Abhishek Gupta","id":"AVGbTCQ2XioLLLZULBAD"}
}

根据update API我的更新请求是:

$ curl -XPOST http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD/_update -d '{
>   "script": {
>     "inline": "ctx._source.n = name",
>     "params": {
>       "name": "Elas"
>     }
>   }
> }'
{"error":"ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]","status":400}

为什么我的请求不好?

Es版本详细信息:

$ curl http://192.168.0.108:9200/
{
  "status" : 200,
  "name" : "Vance Astro",
  "cluster_name" : "dexter-elasticsearch",
  "version" : {
    "number" : "1.7.1",
    "build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
    "build_timestamp" : "2015-07-29T09:54:16Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

1 个答案:

答案 0 :(得分:1)

Scripted updated in ES 1.7.1与ES 2.x略有不同,即ES 2.x中没有inline parameter,而是您这样写:

curl -XPOST http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD/_update -d '{
    "script": "ctx._source.n = name",
    "params": {
      "name": "Elas"
    }
}'