How to make a search result which can filter by options like amazon.com?

Hello
I am building a search project for products with following requirement:

  1. get results by a keyword
  2. then can filter results by some options in the web page.

filter options , for example filter by categories, by brands. For each category and each brand have product quantity displayed in web page. Something like Electronic(10). Electronic is the category name. 10 is the results quantity that is pre-retrieved.

I want to ask which kinds of queries to use with elasticsearch for better performace.

thanks in advacne

Hi,

1°/ For the keyword field you can use a string with a special analyzer

"type": "string" 
"analyzer": "human"

Exemple of applied filters:

				"filter": [
					"lowercase",
					"asciifolding",
					"trim" ]

Then use a multiMatchQuery on the keyword field.

2°/ For filters you can use a not indexed field

"type": "string",
"index": "not_analyzed".

On this filters, use termsQuery to filter documents.

bye
Xavier

Hi xavierfacq

this can be very helpful for me. I am new on elasticsearch.
1st multiMatchQuery with analyzed on related fields.
2nd step using termsQuery with not_analyzed.

Do you have any idea about the quantity for each item. how I can get the quantity for each item?

Actually, I am using a multiMatchQuery without filters to get all docs and then programmingly get the quantity for each item(eg: category), and repeat it when applying to filter. this is duplicated.

there are two queries for each time. one for getting quantity without filter. The second for applying to filter. is there any improving suggest on this?

there is a aggregation api. It can be used to get quantities for each filter item directly ?

For "quantities", you should take a look at Aggregations:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

1°/ You do not have to count yourself, let Elasticsearch do it.
2°/ Note that it's also possible to run multiple query at one, this way you can run 1, 2, 3 or more
queries in only one time. Pretty usefull !

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-multi-search.html

Have fun :wink:

Absolutly, I'll have to read some doc et run some tests queries, but when I'll have understand how does it work, it'll be perfect for what you want to do :wink:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.