![](/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.