简体   繁体   English

Elasticsearch 5.4.0 - 如何向现有文档添加新字段

[英]Elasticsearch 5.4.0 - How to add new field to existing document

In Production, we already had 2000+ documents.在生产中,我们已经拥有 2000 多个文档。 we need to add new field into existing document.我们需要在现有文档中添加新字段。 is it possible to add new field ?是否可以添加新字段? How can i add new field to exisitng field如何向现有字段添加新字段

You can use the update by query API in order to add a new field to all your existing documents:您可以使用按查询更新 API来向所有现有文档添加新字段:

POST your_index/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script": {
    "inline": "ctx._source.new_field = 0",
    "lang": "painless"
  }
}

Note: if your new field is a string, change 0 to '' instead注意:如果您的新字段是字符串,请将0改为''

我们还可以使用 curl 添加新字段并直接在终端中运行以下命令。

curl -X PUT "localhost:9200/you_index/_mapping/defined_mapping" -H 'Content-Type: application/json' -d '{ "properties":{"field_name" : {"type" : type_of_data}} }' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM