小编典典

在Elasticsearch中为具有新类型的现有索引创建映射

elasticsearch

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

有谁知道为什么我不能为Elasticsearch中的现有索引创建映射,而是为新类型创建映射?该类型尚不存在,为什么不呢?也许我想念一些东西,有可能吗?如果是这样,那将如何实现?

谢谢,弗拉基米尔


阅读 273

收藏
2020-06-22

共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"
             }
          }
       }
    }'
  1. 创建类型2
        curl -XPUT "localhost:9200/i1/t2/_mapping" -d'
    {
       "t2": {
          "properties": {
             "field3": {
                "type": "string"
             },
             "field4": {
                "type": "string"
             }
          }
       }
    }'

现在查看mapping(curl -XGET "http://localhost:9200/i1/_mapping"),看来它正在工作。

希望这可以帮助!!谢谢

2020-06-22