![](/img/trans.png)
[英]Need to update the elastic search doc without id field with nodejs client
[英]Update elastic search doc field value for specific fields in all documents
我有这样的文件。
{
"a":"test",
"b":"harry"
},
{
"a":""
"b":"jack"
}
我需要将带有字段a==""
(空字符串)的文档更新为给定索引的所有文档中的默认值,例如null
。 任何帮助表示赞赏。 谢谢
使用带摄取的查询更新
_update_by_query 还可以通过指定如下管道来使用 Ingest Node 功能:
定义管道
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"
}
}
}
}
}'
或者
POST myindex/_update_by_query?pipeline=set-foo
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc['a'].empty",
"lang": "painless"
}
}
}
}
}
}
要查询具有空字符串字段值的文档,即 = ''
我做了,
"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": "*"
}
}
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.