【问题标题】:Creating a mapping for an existing index with a new type in elasticsearch在 elasticsearch 中使用新类型为现有索引创建映射
【发布时间】:2018-12-06 00:15:05
【问题描述】:

我在 elasticsearch 的网站上找到了一篇文章,描述了如何“在不停机的情况下重新索引”,但每次引入需要自定义映射的新元素时,这并不是真的可以接受 (http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/)

有谁知道为什么我不能为现有索引创建映射,而是为 elasticsearch 中的新类型创建映射?该类型尚不存在,为什么不存在呢?也许我错过了一些东西,有可能吗?如果可以,如何实现?

谢谢, 弗拉基米尔

【问题讨论】:

  • 你尝试过做什么?什么不工作?您始终可以创建新类型(使用自己的映射)
  • 这就是重点——我不认为我可以创建具有自己映射的新类型。任何时候我尝试都会收到以下错误:{“error”:“IndexAlreadyExistsException[[tluseravailability] 已经存在]”,“status”:400 }
  • 我想我知道你在做什么,我想验证一下,你能写你用来为类型添加映射的json吗?
  • 这里是: { "mappings" : { "test" : { "properties" : { "test1" : { "type" : "string", "index" : "not_analyzed" }, "test2" : { "type" : "string", "index" : "not_analyzed" } } } } }
  • 那么,您要创建的是新类型吗?你用来创建索引的映射是什么?

标签: elasticsearch


【解决方案1】:

这里是一个简单的例子,在一个索引中创建两个类型映射,(一个接一个)

我使用 i1 作为索引,使用 t1t2 作为类型,

  1. 创建索引

    curl -XPUT "http://localhost:9200/i1"
  2. 创建类型 1

    curl -XPUT "http://localhost:9200/i1/t1/_mapping" -d
    {
       "t1": {
          "properties": {
             "field1": {
                "type": "string"
             },
             "field2": {
                "type": "string"
             }
          }
       }
    }'
  3. 创建类型 2

    curl -XPUT "localhost:9200/i1/t2/_mapping" -d'
    {
       "t2": {
          "properties": {
             "field3": {
                "type": "string"
             },
             "field4": {
                "type": "string"
             }
          }
       }
    }'

现在查看映射(curl -XGET "http://localhost:9200/i1/_mapping"),似乎它正在工作。

希望这会有所帮助!!谢谢

【讨论】:

  • 谢谢。我缺少索引后的类型,并且必须在创建索引后设置映射。
【解决方案2】:

如果您使用的是 Elasticsearch 6.0 或更高版本,一个索引只能有一种类型。 所以你必须为你的第二种类型创建一个索引,或者创建一个包含这两种类型的自定义类型。

更多详情:Removal of multiple types in index

【讨论】:

    猜你喜欢
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2020-09-23
    • 2014-04-15
    • 1970-01-01
    • 2017-03-11
    相关资源
    最近更新 更多