利用kibana 工具,利用_update_by_query 和script 实现修改字段值为null
示例
1、字段类型如下
"字段名称": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
2、dsl语句
POST xxxxx/_update_by_query
{
"query": {
"bool": {
"must": [
{
"range": {
"insert_time": {
"gte": "2024-02-22 00:00:00",
"lt": "2024-02-22 00:01:00"
}
}
}
]
}
},
"script": {
"source": "ctx._source['字段名称'] = null"
}
}
最新版java client api 实现修改字段为null
BulkRequest.Builder br = new BulkRequest.Builder();
br.operations(op -> op
.update(idx -> idx
.index("索引名称")
.id("doc_id").action(
a->a.script(s -> s
.inline(i -> i
.source( "ctx._source['字段名称'] = null")
)
)
)));
BulkRequest bulkRequest = br.build();
BulkResponse result = elasticsearchClient.bulk(bulkRequest);
System.out.println(result.toString());