# Related search in elasticsearch

**URL:** <https://discuss.elastic.co/t/related-search-in-elasticsearch/171469>\
**Category:** Elasticsearch\
**Created:** [March 8, 2019, 10:18am UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469 "2019-03-08T10:18:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anasbk](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@anasbk](https://discuss.elastic.co/u/anasbk)\
**Post date:** [March 8, 2019, 10:18am UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/1 "2019-03-08T10:18:55Z")

</div>

I'm looking for a convenient way to search for related words to a term. For example, If I search for the word "washer", I should be getting related search terms like "dryer" with the lower score thank washer results, It means the washer documents must appear the first and then dryer documents. how can I do this functionality?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 10:32am UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/2 "2019-03-08T10:32:47Z")

</div>

Synonyms is what you are looking for. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html) and [https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-graph-tokenfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-graph-tokenfilter.html)

---

<div class="post-metadata">

**Author:** ![anasbk](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@anasbk](https://discuss.elastic.co/u/anasbk)\
**Post date:** [March 8, 2019, 10:46am UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/3 "2019-03-08T10:46:14Z")

</div>

Thank you !  
And is it possible to set weights for each synonym ,  
for example [dryer:weight1, dishwasher:weight2 ...] if I search for washer  
I want to get washer results first then dryer results then dishwasher results and so on

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 11:00am UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/4 "2019-03-08T11:00:37Z")

</div>

I don't know if there is an "automatic" way to do so. But you can create a bool query with multiple should clauses. Each clause can use different fields.  
Fields can be generated at index time with multiple subfields. Each subfield with its own dictionary. Then you can boost each query to make more relevant one vs the other.

I hope this makes sense.

---

<div class="post-metadata">

**Author:** ![anasbk](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@anasbk](https://discuss.elastic.co/u/anasbk)\
**Post date:** [March 8, 2019, 1:41pm UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/5 "2019-03-08T13:41:41Z")

</div>

Yes , It makes sense, I think I should do this in two queries, the first will fetch synonyms and the second will use the previous result in a bool query with should clauses, is that true ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 2:42pm UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/6 "2019-03-08T14:42:03Z")

</div>

No. One single call should be enough.

---

<div class="post-metadata">

**Author:** ![anasbk](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@anasbk](https://discuss.elastic.co/u/anasbk)\
**Post date:** [March 8, 2019, 3:01pm UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/7 "2019-03-08T15:01:38Z")

</div>

could you please write a query example of that ? I couldn't figure it out !

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2019, 4:11pm UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/8 "2019-03-08T16:11:51Z")

</div>

What did you try so far?

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 5, 2019, 4:11pm UTC](https://discuss.elastic.co/t/related-search-in-elasticsearch/171469/9 "2019-04-05T16:11:56Z")

</div>

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