【问题标题】:Elasticsearch update mapping using json使用 json 的 Elasticsearch 更新映射
【发布时间】:2016-10-21 13:35:31
【问题描述】:

我想将字段的类型从“字符串”更改为“日期”(具体格式:“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 的示例时也遇到了这个问题。

有谁知道怎么回事?

【问题讨论】:

  • 我发现更改字段的 type r 格式不适用于同一索引内的不同文档。解决方案是创建一个新索引并为其提供正确的映射 1. PUT /new_index (创建一个索引 没有 映射) 2. PUT /new_index/_mapping/new_doc -d @new_mapping 然后将旧索引中的所有数据转储到新索引并在新映射中重新索引它们

标签: json elasticsearch elasticsearch-mapping


【解决方案1】:

您需要在您的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

【讨论】:

  • 这个运气好吗?
猜你喜欢
  • 2017-03-11
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多