Problem
Shoppers describe one product in different words: «mobile», «cell phone» and «smartphone». A search that matches only the literal query word misses items whose titles use another variant, so the shopper sees an empty or thin result list. The search must also stay fast while customers combine filters such as brand, category, price and rating.
Example from the article: an e-commerce site lets customers find products by brand ("ABC" or "XYZ"), category ("Electronics", "Shoes"), price (under 200) and a rating of 4 stars or higher.
Solution in brief
Elasticsearch keeps an inverted index per field, mapping each value to the products that contain it, so a query reads a few index entries instead of scanning all products. Synonyms are added through a plain-text synonym file attached to a custom analyzer. The analyzer expands each term at index and query time, so every variant hits the same index entries.
Questions this case answers
- How to make a keyword search treat different words for the same thing as one query without scanning every document
- How to make a product search return the same items for «mobile», «cell phone» and «smartphone»?
- How to keep product search fast when customers filter by brand, category, price and rating?
- How to store and apply a synonym dictionary in Elasticsearch?
Tools and methods
- Elasticsearch — search engine with per-field inverted indexes and configurable analyzers.
- Inverted index — maps each term or attribute value to the products containing it.
- Synonym token filter — expands a term into its synonym group using a file of comma-separated groups.
- multi_match query, cross_fields — query type the article uses to search a field with the expanded terms.
Google or a one-time email code. No password.