简体   繁体   English

更新所有文档中特定字段的弹性搜索文档字段值

[英]Update elastic search doc field value for specific fields in all documents

I have documents like this.我有这样的文件。

{
"a":"test",
"b":"harry"
},
{
"a":""
"b":"jack"
}

I need to update docs with field a=="" (empty string) to default value say null in all documents for a given index.我需要将带有字段a=="" (空字符串)的文档更新为给定索引的所有文档中的默认值,例如null Any help is appreciated.任何帮助表示赞赏。 Thanks谢谢

Use Update by query with ingest使用带摄取的查询更新

_update_by_query can also use the Ingest Node feature by specifying a pipeline like this: _update_by_query 还可以通过指定如下管道来使用 Ingest Node 功能:

define the pipeline定义管道

PUT _ingest/pipeline/set-foo
{
  "description" : "sets foo",
  "processors" : [ {
      "set" : {
        "field": "a",
        "value": null
      }
  } ]
}

then you can use it like:那么你可以像这样使用它:

 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"
                         }
                    }
                }
            }
        }
    }

To query a documents with empty string field value, ie = ''要查询具有空字符串字段值的文档,即 = ''
I did,我做了,

"query": {
  "bool": {
    "must": [
      {
        "exists": {
          "field": "a"
        }
      }
    ],
    "must_not": [
      {
        "wildcard": {
          "a": "*"
        }
      }
      ]
    }
  }

So overall query to update all docs with field a=="" is,因此,使用字段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.

相关问题 需要用 nodejs 客户端更新没有 id 字段的弹性搜索文档 - Need to update the elastic search doc without id field with nodejs client 每次在弹性搜索中插入文档时自动增加字段值 - Auto Increment a field value every time a doc is inserted in elastic search ZCCADCDEDB567ABAE643E15DCF0974E503Z:如何使用今天的日期作为字段值更新集合中的所有文档 - Mongoose : How to update all documents in a collection with todays date as field value MongoDB - 更新集合中的所有文档,使用文档中已存在的另一个字段的值添加新字段 - MongoDB - Update all documents in a collection, adding a new field using value from another field that is already present in the document mongoose:查找所有具有特定字段的文档 - mongoose: find all the documents that have specific field MongoDB:更新所有文档中的字符串字段 - MongoDB: Update a string field in all documents 所有文档中的mongoDB +节点更新字段 - mongoDB + Node update field from all documents 如何通过排除mongodb中的某些字段来搜索特定文档? - How to search specific documents by excluding some fields in mongodb? 如何在弹性搜索中为字段创建自动增量值 - How do I create auto increment value for a field in elastic search Mongoose:findByIdAndUpdate:尝试更新所有带有名称字段(firstName + lastName)的文档 - Mongoose: findByIdAndUpdate: Trying to update all documents with name field (firstName + lastName)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM