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).
Re: Facet autocomplete for field with multiple values
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