简体   繁体   English

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

[英]Creating a mapping for an existing index with a new type in elasticsearch

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/ ) 我在elasticsearch的网站上发现了一篇文章,描述了如何“无需停机时重新编制索引”,但每次引入需要自定义映射的新元素时,这都不是真的可以接受( http://www.elasticsearch.org/blog/changing-映射与零停机时间/

Does anyone know why I can't create a mapping for an existing index but a new type in elasticsearch? 有谁知道为什么我不能为现有索引创建映射,而是在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, 我用i1作为索引, t1t2作为类型,

  1. Create index 创建索引

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

     curl -XPUT "http://localhost:9200/i1/t1/_mapping" -d { "t1": { "properties": { "field1": { "type": "string" }, "field2": { "type": "string" } } } }' 
  3. Create type 2 创建类型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. 现在看一下映射( curl -XGET "http://localhost:9200/i1/_mapping" ),好像它正在工作。

Hope this helps!! 希望这可以帮助!! Thanks 谢谢

If you're using Elasticsearch 6.0 or above, an index can have only one type . 如果您使用的是Elasticsearch 6.0或更高版本, 则索引只能有一种类型 So you have to create an index for your second type or create a custom type that would contain the two types. 因此,您必须为第二种类型创建索引,或者创建包含这两种类型的自定义类型。

For more details : Removal of multiple types in index 有关更多详细信息: 删除索引中的多个类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM