ElasticSearch Sorted Index 无法按预期使用多个分片 [英] ElasticSearch Sorted Index not working as expected with multiple shards

查看:53
本文介绍了ElasticSearch Sorted Index 无法按预期使用多个分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有默认价格排序映射的弹性索引:

I have an elastic index with default sort mapping of price:

shop_prices_sort_index

    "sort" : {
      "field" : "enrich.price",
      "order" : "desc"
    },

如果我插入 10 个文档:

If I insert 10 documents:

100, 98, 10230, 34, 1, 23, 777, 2323, 3, 109

并使用/_search 获取结果.默认情况下,它按价格降序返回文档.

And Fetch results using /_search. By default it returns documents in order of price descending.

10230, 2323...

但是如果我将我的文档分成 3 个分片,那么相同的查询会返回一些其他的产品序列:

But if I distribute my documents into 3 shards, Then the same query returns some other sequence of products:

100, 98, 34...

我真的被困在这里,我不确定我是否遗漏了一些基本的东西,或者我是否需要任何额外的设置才能使排序索引正确运行.

I am really stuck here, I am not sure if I am missing out something basic or Do I need any extra settings to make a Sorted Index behave correctly.

PS:我也尝试过路由"&'偏爱'.但没有运气.非常感谢任何帮助.

PS: I also tried 'routing' & 'preference'. but no luck. Any help much appreciated.

推荐答案

配置时 索引排序,您只需要确保每个分片内的每个段都正确排序.索引排序的目标是在搜索过程中提供一些更多优化

When configuring index sorting, you're only making sure that each segment inside each shard is properly sorted. The goal of index sorting is to provide some more optimization during searches

由于 ES 的分布式特性,当你的索引有很多分片时,每个分片都会被正确排序,但你的搜索查询仍然需要明确使用排序.

Due to the distributed nature of ES, when your index has many shards, each shard will be properly sorted, but your search query will still need to use sorting explicitly.

因此,如果您的索引设置包含以下内容以在索引时应用排序

So if your index settings contains the following to apply sorting at indexing time

"sort" : {
  "field" : "enrich.price",
  "order" : "desc"
}

您的搜索查询还需要在查询时包含相同的排序规范

your search queries will also need to contain the same sort specification at query time

"sort" : {
  "field" : "enrich.price",
  "order" : "desc"
}

通过使用索引排序,您在索引时会遇到一些开销,但最终您的搜索查询会更快一些.

By using index sorting you'll hit a little overhead at indexing time, but your search queries will be a bit faster in the end.

这篇关于ElasticSearch Sorted Index 无法按预期使用多个分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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