0

我想将字段的类型从“字符串”更改为“日期”(具体格式:“epoch_second”)。由于无法更新现有索引的映射,我需要创建一个新索引,我最想使用现有索引中的映射。这是我正在使用的:

curl -XGET ' http://localhost:9200/sam/saga/_mapping?pretty ' >saga.json

将当前索引的映射转储到一个 json 文件中,其内容是这样的:

{
  "sam" : {
    "mappings" : {
      "saga" : {
        "properties" : {
          "name" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

然后我替换

         "name" : {
           "type" : "long"
         }

         "name" : {
           "type" : "date"
         }

并将新文件保存为 saga2.json。然后运行这个

curl -XPUT ' http://localhost:9200/sam/_mapping/saga2 ' -d @saga2.json

但是,当我检查新索引的映射时,现在所有类型都更改为“字符串”。

我什至在使用 Elasticsearch 的示例时遇到了这个问题。

有谁知道出了什么问题?

4

1 回答 1

0

您需要在saga2.json文件中再进行一项更改,即映射类型名称saga-> saga2(现在您可能需要将其全部重命名为saga3

{
  "sam" : {
    "mappings" : {
      "saga2" : {                  <--- here
        "properties" : {
          "name" : {
            "type" : "date"        <--- and here
          }
        }
      }
    }
  }
}

然后只有你可以运行这个:

curl -XPUT 'http://localhost:9200/sam/_mapping/saga2' -d @saga2.json
于 2016-10-22T04:12:11.823 回答