在弹性搜索中创建一个新类型的现有索引的映射 [英] Creating a mapping for an existing index with a new type in elasticsearch

查看:117
本文介绍了在弹性搜索中创建一个新类型的现有索引的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一篇关于elasticsearch的网站的文章描述了如何在没有停机的情况下重建索引,但是每当引入新元素需要自定义映射( http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/



有谁知道为什么我不能为现有索引创建映射,但是在弹性搜索中创建一个新类型?那个类型还不存在,那为什么不呢?也许我错过了一些东西,这是可能的吗?谢谢,
弗拉基米尔

解决方案



/ div>

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



我已经使用了 i1 作为索引, t1 t2 作为类型,


  1. 创建索引

      curl -XPUThttp:// localhost:9200 / i1 


  2. 创建类型1

      curl -XPUThttp:// localhost:9200 / i1 / t1 / _mapping-d 
    {
    t1:{
    properties :{
    field1:{
    type:string
    },
    field2:{
    type:string
    }
    }
    }
    }'


  3. 创建类型2

      curl -XPUTlocalhost:9200 / i1 / t2 / _mapping-d'
    {
    t2:{
    property:{
    field3:{
    type:string
    },
    field4:{
    type:string
    }
    }
    }
    }'


现在看看映射( curl -XGEThttp:// localhost:9200 / i1 / _mapping),似乎是加工。



希望这有帮助!谢谢


I found an article on elasticsearch's site describing how to 'reindex without downtime', but that's not really acceptable every time a new element is introduced that needs to have a custom mapping (http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/)

Does anyone know why I can't create a mapping for an existing index but a new type in elasticsearch? The type doesn't exist yet, so why not? Maybe I'm missing something and it IS possible? If so, how can that be achieved?

Thanks, Vladimir

解决方案

Here is a simple example to create two type mapping in a index, (one after another)

I've used i1 as index and t1 and t2 as types,

  1. Create index

    curl -XPUT "http://localhost:9200/i1"

  2. Create type 1

    curl -XPUT "http://localhost:9200/i1/t1/_mapping" -d
    {
       "t1": {
          "properties": {
             "field1": {
                "type": "string"
             },
             "field2": {
                "type": "string"
             }
          }
       }
    }'

  3. Create type 2

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

Now Looking at mapping( curl -XGET "http://localhost:9200/i1/_mapping" ), It seems like it is working.

Hope this helps!! Thanks

这篇关于在弹性搜索中创建一个新类型的现有索引的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆