# Dynamic query-time synonyms

**URL:** <https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883>\
**Category:** Elasticsearch\
**Created:** [September 19, 2016, 1:02pm UTC](https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883 "2016-09-19T13:02:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [September 19, 2016, 1:02pm UTC](https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883/1 "2016-09-19T13:02:13Z")

</div>

I'm doing synonyms but for different reasons (many users in 1 index each with different synonyms) I need to handle synonyms only at query time. What is the best way to do this currently in es ?

Currently I'm thinking a process like:

1. analyze query and get tokens from es without searching
2. check tokens with other db for synonyms
3. rebuild query to es with synonyms for the current tokens included

Does this make sense ? Am I missing something? How would I do step 3 ?

Thanks!

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [September 19, 2016, 1:56pm UTC](https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883/2 "2016-09-19T13:56:44Z")

</div>

> [@ddorian43](#):
>
> How would I do step 3

You might want to checkout

> **[Expand or contract | Elasticsearch: The Definitive Guide \[2.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html)**

To quote from the page linking to that: [Expand or contract | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms-expand-or-contract.html)

> Alternatively, if we don’t use synonyms at index time, then at search time, we would need to convert a query for English into a query for english OR british.

As a side question: What's your reason for having multiple users in one index?

Hope this helps,  
Isabel

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [September 19, 2016, 2:35pm UTC](https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883/3 "2016-09-19T14:35:52Z")

</div>

@mainec  
Because the number of users is big (at least thousands, hopefully low million) and I can't have that many indexes/shards because of the overhead.

I'll check it out and reply again if I still have questions.

---

<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:** [July 5, 2017, 10:19pm UTC](https://discuss.elastic.co/t/dynamic-query-time-synonyms/60883/4 "2017-07-05T22:19:07Z")

</div>


