Elastic Search, Nest. functional sorting

时间:2015-11-12 10:45:49

标签: nest elasticsearch

I'm building a filter page, with facets etc, which works as it should. Now the our customer has a request to, basically "Be able to decide which sorting the items comes out in". Each product is decorated with a Product Display Order, and is in a Product Line.

We got these example Product Display Orders: 1. Featured Item 2. Core Item 3. Spare Part 4. Utility

And these Product Lines: 1. Hammers 2. Saw 3. Wood

and the sorting is like this: Sorting should firstly be based on Product Display Orders, secondly by product lines, thirdly Alphabetically. So all products which is a Featured Item is listed first, and all these Featured Items is then sorted by their product line, and if some product are in the same Featured Item and Product Line, then its alphabetically.

The challenge is: I can't just get the sorting of Product Display order items and product lines as a number on the product, i only got a name/id.

We've thought of Boosting based on if the product are in the different categories, but it seems a bit messy.

OR

See if it possible to have some logic in the Sorting. Sort by productDisplayOrder: 1. featured, 2. core Item ... Then by ProductLines: 1. Hammers, 2. Saw ... Then by Name DESC.

Which way is the best way to have this sorting, is it possible to give this logic to elastic, if it is a match and then sort it. Or are we needed to twist the boosts of product?

Hopefully this makes sense for you. Thanks in advance! :)

1 个答案:

答案 0 :(得分:2)

选项1)。最快/性能最佳的解决方案是为productDisplayOrderProductLine创建新的/单独的整数字段,然后按照描述的排序条件使用这些字段(在重新索引和验证数据按预期编制索引之后)。

选项2)如果您想要比描述更多的细微差别(例如,更高的得分匹配可以突破'所描述的排序上限),那么您可以使用Function Score Query 进行探索以实施自定义评分策略在生成总体匹配分数时需要考虑productDisplayOrderProductLine

选项3)。如果您无法更改映射并重新索引数据,则可以使用Script-Based Sorting使用脚本(例如Groovy)从当前索引的productDisplayOrder / ProductLine文本生成排序值。请记住,查询性能将比前两个选项更差。