How to get only matched value for field that has multiple values

Let's say I have a document with a type as you go field that has multiple values.

tags : ["cool beans", "great job", hello there"]

I do a phrase prefix search with the term "coo". I want to display the user "cool beans" as the match. However, the current query returns all 3 values for the tag field since it matched on the document.

Hi @elasticfan1

One way would be to use a nested field and through the nested query and inner_hits you would be able to know which element of the array was the match.

If you choose to use an array, you won't be able to get the element because you'll be returning all of them in the document, so you'd have to implement a logic in your application to identify which element of the array was the match.

Looking at the docs, I could use a completion suggester to solve this issue. However, the completion suggester doesn't query mid sentence.

tags : ["cool beans", "great job", hello there"]

a suggest of "beans" won't return anything.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.