An array field in elasticsearch that returns only matching elements

I have an index in elasticsearch (bus) with an array field and a custom analyzer for ngram with min_ngram = 1 and max_ngram = 10.

Field example

field1: [foo, bar, bof] 

I create a query with the value of field1 'f' and returns documents containing 'f' in one of the values ​​in field1.

Question: Is it possible to return only matching values ​​in an array, for example. in the case of field 1 and the query 'f', only "foo" and "bof" will be returned, and "bar" will be closed, for example. field1: [foo, bof]?

+8
source share
3 answers

You can use hihglighting based on the results and get the part where the query matches string fields. The backlight should be able to determine which terms all match.

+1
source

If it is a nested type, you can do it using internal hits.

0
source

You can achieve this by applying a marker in an elastic search query. where in the answer you will receive an additional selection field with only the corresponding values.

0
source

All Articles