ElasticSearch 排序索引无法按预期使用多个分片
ElasticSearch Sorted Index not working as expected with multiple shards
我有一个带有默认价格排序映射的弹性索引:
shop_prices_sort_index
"sort" : {
"field" : "enrich.price",
"order" : "desc"
},
如果我插入 10 个文档:
100, 98, 10230, 34, 1, 23, 777, 2323, 3, 109
并使用 /_search 获取结果。默认情况下,它 returns 按价格降序排列文件。
10230, 2323...
但是如果我将我的文档分布到 3 个分片中,那么相同的查询 returns 一些其他的产品序列:
100, 98, 34...
我真的卡在这里了,我不确定我是否遗漏了一些基本的东西,或者我是否需要任何额外的设置才能使排序索引正常运行。
PS:我也试过'routing'和'preference'。但没有运气。
非常感谢任何帮助。
配置时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 的分布式特性,当你的索引有很多分片时,每个分片都会被正确排序,但你的搜索查询仍然需要明确地使用排序。
因此,如果您的索引设置包含以下内容以在索引时应用排序
"sort" : {
"field" : "enrich.price",
"order" : "desc"
}
您的搜索查询还需要在查询时包含相同的排序规范
"sort" : {
"field" : "enrich.price",
"order" : "desc"
}
通过使用索引排序,您在编制索引时会遇到一些开销,但最终您的搜索查询会更快一些。
我有一个带有默认价格排序映射的弹性索引:
shop_prices_sort_index
"sort" : {
"field" : "enrich.price",
"order" : "desc"
},
如果我插入 10 个文档:
100, 98, 10230, 34, 1, 23, 777, 2323, 3, 109
并使用 /_search 获取结果。默认情况下,它 returns 按价格降序排列文件。
10230, 2323...
但是如果我将我的文档分布到 3 个分片中,那么相同的查询 returns 一些其他的产品序列:
100, 98, 34...
我真的卡在这里了,我不确定我是否遗漏了一些基本的东西,或者我是否需要任何额外的设置才能使排序索引正常运行。
PS:我也试过'routing'和'preference'。但没有运气。 非常感谢任何帮助。
配置时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 的分布式特性,当你的索引有很多分片时,每个分片都会被正确排序,但你的搜索查询仍然需要明确地使用排序。
因此,如果您的索引设置包含以下内容以在索引时应用排序
"sort" : {
"field" : "enrich.price",
"order" : "desc"
}
您的搜索查询还需要在查询时包含相同的排序规范
"sort" : {
"field" : "enrich.price",
"order" : "desc"
}
通过使用索引排序,您在编制索引时会遇到一些开销,但最终您的搜索查询会更快一些。