我有这样的文件。
{
"a":"test",
"b":"harry"
},
{
"a":""
"b":"jack"
}
我需要在给定索引的所有文档中将字段a==""
(空字符串)的文档更新为默认值,例如null
。
任何帮助表示赞赏。谢谢
答案 0 :(得分:1)
_update_by_query也可以通过指定如下管道来使用“摄取节点”功能:
定义管道
PUT _ingest/pipeline/set-foo
{
"description" : "sets foo",
"processors" : [ {
"set" : {
"field": "a",
"value": null
}
} ]
}
然后您可以像使用它一样
POST myindex/_update_by_query?pipeline=set-foo
{
"query": {
"filtered": {
"filter": {
"script": {
"script": "_source._content.length() == 0"
}
}
}
}
}'
OR
POST myindex/_update_by_query?pipeline=set-foo
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc['a'].empty",
"lang": "painless"
}
}
}
}
}
}
答案 1 :(得分:0)
要查询具有空字符串字段值的文档,即= ''
我做到了,
"query": {
"bool": {
"must": [
{
"exists": {
"field": "a"
}
}
],
"must_not": [
{
"wildcard": {
"a": "*"
}
}
]
}
}
因此用于更新所有具有字段a==""
的所有文档的查询是
POST test11/_update_by_query
{
"script": {
"inline": "ctx._source.a=null",
"lang": "painless"
},
"query": {
"bool": {
"must": [
{
"exists": {
"field": "a"
}
}
],
"must_not": [
{
"wildcard": {
"a": "*"
}
}
]
}
}
}