【问题标题】:Update a field from a Elasticsearch document更新 Elasticsearch 文档中的字段
【发布时间】:2020-02-26 21:29:32
【问题描述】:

我需要更新索引到 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
}

提前致谢!

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您可以做的是将您的数据 _reindex 到目标索引,删除您的原始索引,然后再次 _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
    

    很高兴有解决方案

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-13
        • 1970-01-01
        相关资源
        最近更新 更多