如何在Opensearch/Elasticsearch中更新字段格式?

zvms9eto  于 2023-01-08  发布在  ElasticSearch
关注(0)|答案(1)|浏览(194)

我正在尝试更改opensearch中string字段的格式:

PUT my_index/_mapping
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "YYYY-MM-DD HH:mm:ss.SSS"
      }
    }
  }
}

回答是

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [mappings : {properties={timestamp={format=YYYY-MM-DD HH:mm:ss.SSS, type=date}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Root mapping definition has unsupported parameters:  [mappings : {properties={timestamp={format=YYYY-MM-DD HH:mm:ss.SSS, type=date}}}]"
  },
  "status" : 400
}

我花了几天时间试图弄清楚这一点,在我看来,开放搜索只是如此不必要的复杂。

zc0qhyus

zc0qhyus1#

现有字段一旦创建,就不能更改其类型。您需要将Map错误的索引重新索引为Map正确的新索引。
首先,创建新索引:

PUT new_index
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "YYYY-MM-DD HH:mm:ss.SSS"
      }
    }
  }
}

然后,将旧索引重新编入新索引

POST _reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}

相关问题