# Genre Expansion in Elasticsearch 6.1

**URL:** <https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710>\
**Category:** Elasticsearch\
**Created:** [January 16, 2018, 12:39pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710 "2018-01-16T12:39:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![acorned](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@acorned](https://discuss.elastic.co/u/acorned)\
**Post date:** [January 16, 2018, 12:39pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/1 "2018-01-16T12:39:51Z")

</div>

Hello All!

I need some hierarchical structure of synonyms to search, as it described here:  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html)

When I search for "pet" I want to find documents with "cat" and "dog", and so on. Is it possible in Elastic 6.1? Could you give me an example?

---

<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:** [January 16, 2018, 1:44pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/2 "2018-01-16T13:44:49Z")

</div>

Yes. Use a Synonym TokenFilter in your analyzer. [https://www.elastic.co/guide/en/elasticsearch/reference/6.1/analysis-synonym-tokenfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/analysis-synonym-tokenfilter.html)

---

<div class="post-metadata">

**Author:** ![acorned](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@acorned](https://discuss.elastic.co/u/acorned)\
**Post date:** [January 22, 2018, 1:20pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/3 "2018-01-22T13:20:26Z")

</div>

I tried Synonym TokenFilter, but I can't make it hierarchical. For example, if I write something like this in Solr:

```
pet => cat, dog, bird
cat => kitten, kitty
dog => chow chow, malamute
bird => parrot, hawk

```

and try to search "pet" I'll find documents with "cat" and "dog" inside, but not with "chow chow". Of course I can write all the downgrade synonyms in one string, but if I try to add about 70\_000 low level synonyms, Elasticsearch doesn't create index (I waited for hour, nothing has changed).

I read about Synonym Graph Token Filter that could be useful, but I can't find proper realization(

---

<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:** [January 22, 2018, 1:44pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/4 "2018-01-22T13:44:04Z")

</div>

> I read about Synonym Graph Token Filter that could be useful, but I can't find proper realization(

Do you mean this? [Synonym Graph Token Filter | Elasticsearch Reference [6.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/analysis-synonym-graph-tokenfilter.html)

But anyway, I "think" that it should behave the same way as Solr does. But I'm not quite an expert on that part. May be @jimczi could tell more?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [January 22, 2018, 2:38pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/5 "2018-01-22T14:38:17Z")

</div>

The example on the guide is a bit misleading. It's not a hierarchical structure, only one rule gets applied.  
The idea of this example is to show how to do rewrite a single term into multiple terms. `cat` is rewritten to `cat` and `pet` and `kitten` is expanded to `cat`, `pet`, `kitten`. As you can see each rule in the example contains all expansions.  
Now it becomes tricky when you mix indexation and querying. If you set a synonym filter with your example rules at indexing **and** query time then a document that contains `pet` would index `cat, dog, bird` and when querying for `pet` you would in fact search for `cat, dog, bird`. Though documents that contain `dog` are already rewritten into `chow chow, malamute` so `dog` would never match. The `synonym_graph` is not useful for this, you should revise your rules based on how the synonyms are applied.

---

<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:** [February 19, 2018, 2:38pm UTC](https://discuss.elastic.co/t/genre-expansion-in-elasticsearch-6-1/115710/6 "2018-02-19T14:38:17Z")

</div>

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