POST orders/_update_by_query
{
"script" : "ctx._source.geoip += newElement",
"params": {
"newElement": {
"location" : "[40.730610, -73.935242]"
}
},
"query": {
"term": {
"CITY": {
"value": "nyc"
}
}
}
}
上面抛出错误[params]中START_OBJECT的未知键。
POST orders/_update_by_query
{
"script":{
"source":
"for (item in ctx._source.geoip){item.location = '[40.730610, -73.935242]'}",
"lang":"painless"
},
"query": {
"term": {
"CITY": {
"value": "nyc"
}
}
}
}
以上抛出空指针异常,并指向source.geoip的句点
这是我的映射:
{
"orders" : {
"mappings" : {
"properties" : {
"geoip" : {
"dynamic" : "true",
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}
}
第一种方法中的几个问题:
params
需要在脚本对象内定义,而不是在其下定义newElement
需要使用params.newElement
进行访问+= params.newElement
附加到不存在的ctx._source.geoip
location
是geo_point
类型,因此,[40.730610, -73.935242]
([lon, lat]
)或"-73.935242,40.730610"
("lat,lon"
),但不能同时包含两者]]工作命令:
POST orders/_update_by_query
{
"script": {
"inline": "ctx._source.geoip = params.newElement",
"params": {
"newElement": {
"location": [
40.73061,
-73.935242
]
}
}
},
"query": {
"term": {
"CITY": {
"value": "nyc"
}
}
}
}