1ns*_*nct 1 field elasticsearch elastica
我想知道Elastica或ElasticSearch是否能够从给定索引中的所有文档中删除单个字段.我在REST API中找到了正确的方法,但在尝试使用它时,它会产生语法错误.
我写
curl -XPOST localhost:9200/products/product/O2bMZYRek5/_update -d '{
"script": "ctx._source.remove("Color")"
}'
Run Code Online (Sandbox Code Playgroud)
哪个回来了
{"error":"JsonParseException[Unexpected character ('C' (code 67)): was expecting comma to separate OBJECT entries\n at [Source: [B@fddc294; line: 2, column: 32]]","status":500}
Run Code Online (Sandbox Code Playgroud)
你可以通过http api做到这一点:
curl -XPOST 'http://localhost:9200/goods_city_1/meirong/552899/_update' -d '{
"script" : "ctx._source.remove(\"text\")"
}'
Run Code Online (Sandbox Code Playgroud)
或者您可以通过java api执行此操作:
StringBuilder sb = new StringBuilder();
for(String stringField : stringFields){
sb.append("ctx._source.remove(\"").append(stringField).append("\");");
}
updateRequestBuilder.setScript(sb.toString());
Run Code Online (Sandbox Code Playgroud)
我试过这个,它会起作用.(至少0.90.2.)
如果你需要它适用于索引中的所有doc,你应该将所有这些更新操作(或每5000个动作)放入一个BulkRequest,然后将其抛给服务器.
或者也许"elasticsearch-reindex"(https://github.com/karussell/elasticsearch-reindex)可以帮助您,如果您使用别名来接近您的数据.
| 归档时间: |
|
| 查看次数: |
6910 次 |
| 最近记录: |