# Facet autocomplete for field with multiple values

**URL:** <https://discuss.elastic.co/t/facet-autocomplete-for-field-with-multiple-values/15063>\
**Category:** Elasticsearch\
**Created:** [December 31, 2013, 2:25pm UTC](https://discuss.elastic.co/t/facet-autocomplete-for-field-with-multiple-values/15063 "2013-12-31T14:25:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![piotrekpmj](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@piotrekpmj](https://discuss.elastic.co/u/piotrekpmj)\
**Post date:** [December 31, 2013, 2:25pm UTC](https://discuss.elastic.co/t/facet-autocomplete-for-field-with-multiple-values/15063/1 "2013-12-31T14:25:37Z")

</div>

Hi,

I have problem finding solution for specific usage scenario where I want to  
autocomplete facet for field that has array of values.

Documents in my index are some objects that can be owned by 0..n people, so  
I have field 'owner' containing zero to few strings of following format:  
first\_name [second\_name] last\_name (user\_id). Since there are lots of  
objects and many owners, I don't like idea of loading all owners onto  
webpage and make some client-side filtering, so I wanted to use  
autocomplete feature. Since I have owners in such format, even prefix  
search doesn't work for me since user can type last name of owner which is  
some n-th word in string. Second thing is that I need autocomplete to  
respond with whole field values that will properly match facet filter. So I  
would like to get 'John Doe (p000001)' for all queries like 'John', 'Doe',  
'Joh', 'p000001'.

I was thinking of some approaches, but all have some drawbacks:

1. Completion suggester - everything fine except I won't be able to search  
by last\_name or user\_id.
2. Phrase suggester with shingles - as far as I know it will allow me to  
have google-kind autocomplete, but it will only give me parts of field  
value beginning with provided text (so if for 'John Doe (p000001)' I would  
query 'Doe', I expect to get 'Doe' and 'Doe (p000001)' which is not what I  
need).
3. Regex query - here I can make a successful query, but ES will respond  
with whole documents (which is firstly too heavy) and those documents will  
contain whole arrays of owners and I would be forced to filter them in  
code to get only those owners that are matching the query. Finally it would  
work, but way too much overhead.

Please help in any way (even if you would that there is no way it is better  
than no response).

Regards,  
Peter.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6ccaa79e-f4fd-43c0-bbfd-8282bfc1f19d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6ccaa79e-f4fd-43c0-bbfd-8282bfc1f19d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![speedblue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/speedblue/32/1893_2.png) [@speedblue](https://discuss.elastic.co/u/speedblue)\
**Post date:** [January 2, 2014, 10:55am UTC](https://discuss.elastic.co/t/facet-autocomplete-for-field-with-multiple-values/15063/2 "2014-01-02T10:55:52Z")

</div>

Hi Peter,

I don't see any magic solution with your current structure but it would be easier if you structure your data in the opposite way:

- Index one document per user with all users information (firstname, lastname, uid, ...)
- On each user object add the list of your document ID that the user owns in a 'documents' attribute

In that case, you are now in a standard usecase where you can use a prefix query or ngram and filter by document ID (prefix query and ngrams are well covered here: [http://jontai.me/blog/2013/02/adding-autocomplete-to-an-elasticsearch-search-application/](http://jontai.me/blog/2013/02/adding-autocomplete-to-an-elasticsearch-search-application/))

Best  
Julien

---

<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, 1:58am UTC](https://discuss.elastic.co/t/facet-autocomplete-for-field-with-multiple-values/15063/3 "2017-07-06T01:58:41Z")

</div>


