# Get matching term

**URL:** <https://discuss.elastic.co/t/get-matching-term/4894>\
**Category:** Elasticsearch\
**Created:** [July 19, 2011, 8:03am UTC](https://discuss.elastic.co/t/get-matching-term/4894 "2011-07-19T08:03:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pau/32/3168_2.png) [@Pau](https://discuss.elastic.co/u/Pau)\
**Post date:** [July 19, 2011, 8:03am UTC](https://discuss.elastic.co/t/get-matching-term/4894/1 "2011-07-19T08:03:54Z")

</div>

Hi!

I have a document that have some tags for instance.

{name: 'foo', tags: ['black', 'green', 'yellow', 'saturday night  
fever']}

The tags are not known, a user can insert anything.

I want to provide autocompletion so users can reuse tags already used  
by others. To do so I do a prefix query.

I would love if the query could also return the original term that  
matched the query. In the example above, if I search for 'satur' I  
would like to get 'saturday night fever' tag instead of the whole  
document.

Is there any way to achieve that?

Thank's in advance!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 19, 2011, 9:41pm UTC](https://discuss.elastic.co/t/get-matching-term/4894/2 "2011-07-19T21:41:18Z")

</div>

There isn't a way to do it, unless you create an autocomplete index with  
tags as documents, or maybe do the matching yourself on the client side (if  
its a prefix based one, its simple).

On Tue, Jul 19, 2011 at 11:03 AM, Pau [masylum@gmail.com](mailto:masylum@gmail.com) wrote:

> Hi!
> 
> I have a document that have some tags for instance.
> 
> {name: 'foo', tags: ['black', 'green', 'yellow', 'saturday night  
> fever']}
> 
> The tags are not known, a user can insert anything.
> 
> I want to provide autocompletion so users can reuse tags already used  
> by others. To do so I do a prefix query.
> 
> I would love if the query could also return the original term that  
> matched the query. In the example above, if I search for 'satur' I  
> would like to get 'saturday night fever' tag instead of the whole  
> document.
> 
> Is there any way to achieve that?
> 
> Thank's in advance!

---

<div class="post-metadata">

**Author:** ![Pau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pau/32/3168_2.png) [@Pau](https://discuss.elastic.co/u/Pau)\
**Post date:** [July 19, 2011, 10:32pm UTC](https://discuss.elastic.co/t/get-matching-term/4894/3 "2011-07-19T22:32:54Z")

</div>

I´m currently doing it client side but it feels kind of "hackish". I  
would probably store the tags in a different index as you said. 🙂

On Jul 19, 11:41 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> There isn't a way to do it, unless you create an autocomplete index with  
> tags as documents, or maybe do the matching yourself on the client side (if  
> its a prefix based one, its simple).
> 
> On Tue, Jul 19, 2011 at 11:03 AM, Pau [masy...@gmail.com](mailto:masy...@gmail.com) wrote:
> 
> > Hi!
> 
> > I have a document that have some tags for instance.
> 
> > {name: 'foo', tags: ['black', 'green', 'yellow', 'saturday night  
> > fever']}
> 
> > The tags are not known, a user can insert anything.
> 
> > I want to provide autocompletion so users can reuse tags already used  
> > by others. To do so I do a prefix query.
> 
> > I would love if the query could also return the original term that  
> > matched the query. In the example above, if I search for 'satur' I  
> > would like to get 'saturday night fever' tag instead of the whole  
> > document.
> 
> > Is there any way to achieve that?
> 
> > Thank's in advance!

---

<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 6, 2017, 4:00am UTC](https://discuss.elastic.co/t/get-matching-term/4894/4 "2017-07-06T04:00:05Z")

</div>


