在修改现有弹性搜索映射时在字段上添加默认值

Alw*_*nny 5 elasticsearch

假设我有一个弹性搜索索引,上面有大约 1000 万个文档。现在我需要is_hotel_type=0为每个 ES 文档添加一个具有默认值的新文件。稍后我会根据我的要求更新。

为此,我使用如下 PUT 请求修改了 myindex-

PUT myindex
{
  "mappings": {
    "rp": {
      "properties": {
        "is_hotel_type": {
          "type": "integer" 
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后使用 POST 运行无痛脚本查询以使用值更新所有现有文档 is_hotel_type=0

POST myindex/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script" : "ctx._source.is_hotel_type = 0;"
}
Run Code Online (Sandbox Code Playgroud)

但是这个过程对于10M文档的大索引来说是非常耗时的。通常我们可以在创建新列时在 SQL 上设置默认值。所以我的问题 - 在Elasticsearch 中是否有任何方法,以便我可以添加一个具有默认值的新字段。我已经尝试过下面的 PUT 请求,null_value但它不起作用。

PUT myindex/_mapping/rp
{
  "properties": {
        "is_hotel_type": {
          "type": "integer",
           "null_value" : 0 
        }
      }
}
Run Code Online (Sandbox Code Playgroud)

我只想知道有没有其他方法可以在没有脚本查询的情况下做到这一点?