V
V
Valery2016-12-16 14:21:22
Online shopping
Valery, 2016-12-16 14:21:22

How to display multiple products from different categories on Elasticsearch?

Hello,
there is an online store with ~1000 suppliers. Each can have from 100 to 10,000 items.
I do a search on the site through Elasticsearch 5.1.1. The indexes are approximately the following:
suppliers:
- title
goods:
- supplier_id
- title
I connected Russian morphology, everything works great. But the problem is that due to the abundance of goods from each supplier, one supplier in the search results can occupy the first few pages.
Considering that few people go beyond the first page, it turns out that specific suppliers get an advantage. I would like to avoid this.
I can do a random sort based on the session, but the relevancy is lost because of this, and for the query "children's clothing", children's products may go to the bottom, and just clothes will rise up.
Ideally, I want to rotate providers in the search results while maintaining relevance.
Now:
- Item from vendor 1
- Item from vendor 1
- Item from vendor 1
- Item from vendor 1
- Item from vendor 2
- Item from vendor 2
- Item from vendor 2
- Item from vendor 2
Do you want:
- Item from vendor 1
- Item from vendor 2
- Item from vendor 1
- Item from vendor 2
- Item from vendor 3
- Product from supplier 4
....
You can get the full search result and sort it in PHP, but this is somehow barbaric. I'm sure there must be ways to do this through elastic. Can someone come across and tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kotofey, 2016-12-16
@Akuma

Aggregate queries like " Top hits Aggregation " should work for you.
The point is that in such a query you specify the field by which you want to group the data (in your case, the supplier field) and you can set the number of documents for each such grouping, for example. 2-3 (will depend on the number of results you display per page).
As a result of such a request, you will receive top 2-3 results for each supplier, and using PHP methods, you can randomly mix them up and give them to the user.

A
Alexey Cheremisin, 2016-12-16
@leahch

When uploading data, enter the rnd field, with a random number from 0 to 100.
If uploading via bulk, you can use the script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question