我需要从满足条件的数组中删除对象,我能够根据条件更新数组的对象,如下所示:
PUT twitter/twit/1
{"list":
[
{
"tweet_id": "1",
"a": "b"
},
{
"tweet_id": "123",
"a": "f"
}
]
}
POST /twitter/twit/1/_update
{"script":"foreach (item :ctx._source.list) {
if item['tweet_id'] == tweet_id) {
item['new_field'] = 'ghi';
}
}",
"params": {tweet_id": 123"}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的
删除我这样做
POST /twitter/twit/1/_update
{ "script": "foreach (item : ctx._source.list) {
if item['tweet_id'] == tweet_id) {
ctx._source.list.remove(item);
}
}",
"params": { tweet_id": "123" }
}
Run Code Online (Sandbox Code Playgroud)
但是这不起作用并且给出了这个错误,
ElasticsearchIllegalArgumentException [无法执行脚本]; 嵌套:ConcurrentModificationException; 错误:ElasticsearchIllegalArgumentException [无法执行脚本]; 嵌套:ConcurrentModificationException
我可以使用删除整个数组或整个字段
"script": "ctx._source.remove('list')"
Run Code Online (Sandbox Code Playgroud)
我也可以通过使用指定对象的所有键来从数组中删除对象
"script":"ctx._source.list.remove(tag)",
"params" : {
"tag" …Run Code Online (Sandbox Code Playgroud) 我正在使用请求nodejs模块来获取网站的html,如下所示:
var request = require('request');
request("http://www.thenewschool.org/", function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log("body>>>>>>>>>>");
} else {
console.log("error>>>>>>>>>"+error);
console.log("response statusCode>>>>>>>>>"+response.statusCode);
console.log("response body>>>>>>>>>"+response.body);
}
})
Run Code Online (Sandbox Code Playgroud)
这给了我这个输出
错误>>>>>>>>>空
响应statusCode >>>>>>>>> 403
响应正文>>>>>>>>>抱歉,由于用户代理无效,此请求已被阻止.
这种情况在大多数情况下都会过去,但在这种情况下失败,有人可以帮助我解决这个问题.