繁体   English   中英

更新 Elasticsearch 文档中的字段

[英]Update a field from a Elasticsearch document

我需要更新索引为 Elasticsearch 的文档中的一个字段。 我该怎么做。

"redcash_sale": {
"type": "object"
}

将上面的字段更新到下面(使启用为 false):-

sale_property_development_j/_mapping/property

{
  "properties": {
    "redcash_sale": {
      "type": "object",
      "enabled": false
    }
  }
}

当我再次映射到 elasticsearch 时引发错误:-

错误

{
"error": {
"root_cause": [
{
"type": "mapper_exception",
"reason": "Can't update attribute for type [_doc.redcash_sale.enabled] in index mapping"
}
],
"type": "mapper_exception",
"reason": "Can't update attribute for type [_doc.redcash_sale.enabled] in index mapping"
},
"status": 500
}

提前致谢!

您可以做的是将您的数据_reindex到 dest 索引,删除原始索引,然后使用新映射再次_reindex到原始索引。

重新索引:

POST _reindex   
{
  "source": {
    "index": "sale_property_development_j"
  },
  "dest": {
    "index": "new_sale_property_development_j"
  }
}

删除原始索引:

DELETE sale_property_development_j

创建请求的映射:

PUT sale_property_development_j
{
   "mappings":{
     "property":{
       "properties": {
         "redcash_sale": {
           "type": "object",
           "enabled": false
          }
       }
     }
  }
}

再次重新索引:

POST _reindex?wait_for_completion=false    
{
  "source": {
    "index": "new_sale_property_development_j"
  },
  "dest": {
    "index": "sale_property_development_j"
  }
}

最后:

DELETE new_sale_property_development_j

很高兴有解决方案

根据: https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html

无法使用 PUT 映射 API 更新已启用。

然后你必须重新索引你的数据。

暂无
暂无

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

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