首页 文章

使用json进行Elasticsearch更新映射

提问于
浏览
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

但是,当我检查新索引的映射时, all 类型现在已更改为"string" .

我甚至使用Elasticsearch的例子来解决这个问题 .

有谁知道什么是错的?

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
    

相关问题