如何在现有索引上设置Elasticsearch路由? [英] How to set up elasticsearch routing on existing index?

查看:279
本文介绍了如何在现有索引上设置Elasticsearch路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引,该索引使用elasticsearch的默认路由。现在我要设置自己的路由,如何实现呢?

I have an index which uses the default routing of elasticsearch. Now I want to set up my own routing, how do I implement this?

官方文档是:

$ curl -XPUT 'http://localhost:9200/store/order/_mapping' -d '
{
   "order":{
      "_routing":{
         "required":true,
         "path":"customerID"
      }
   }
}

执行完此操作后,是否需要重新索引甚至重建整个索引?

After doing this, do I need to reindex of even rebuild the whole index?

推荐答案

如果若要更改现有映射类型中的路由行为,则需要创建一个新索引,重新创建该映射类型并为数据重新索引。我认为甚至无法更改现有映射类型的 _routing 。即使您看到 acknowledted:true ,即使 _routing 部分也可能被完全忽略了。您可以执行上面的update mapping命令,然后检查映射以查看您的映射类型是否具有新的 _routing ,但我敢肯定不会。

If you want to change the routing behavior in an existing mapping type, you need to create a new index, recreate the mapping type and re-index your data. I don't think it's even possible to change the _routing on an existing mapping type. Even if you see acknowledged: true, the _routing part will probably have been ignored altogether. You can execute your update mapping command above, and then check the mapping to see if your mapping type has the new _routing, but I'm pretty sure it won't.

原因与路由的工作方式有关。如果可以动态更新路由,则最终可能会使同一文档位于相同索引的两个不同分片上。第一次为文档建立索引(不带路由),该文档可能以shard1结尾,然后,第二次为文档建立索引(带路由),同一文档可能以shard3结尾。这意味着您的索引中会有一个重复的文档,这可能不是您所希望的行为。

The reason has to do with how the routing works. If it was possible to update the routing dynamically, you could end up with the same document being on two different shards of the same index. The first time you indexed the document (without routing), the document might have ended up on shard1, then then second time you index the document (with routing), the same document might end up on shard3. This means you'd have a duplicate document in your index, which is probably not the desired behavior.

由于很容易创建新的索引和映射类型,因此有疑问,只需从头开始创建一个全新的索引并重新索引您的数据即可。弄清楚查询为何返回奇怪结果的原因,您将花费更少的时间。

Since it's easy to create new indices and mapping types, whenever in doubt, just create a brand new index from scratch and re-index your data. You'll lose less time figuring out why your query returns weird results.

这篇关于如何在现有索引上设置Elasticsearch路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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