Facet autocomplete for field with multiple values

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.
To view this discussion on the web visit 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.

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/)

Best
Julien