Highlighting a field with values from multiple other fields

Hi there,

is it somehow possible to highlight text from a field with values from multiple other fields?
For example:

"Text": "The dog eats an apple under a pine tree."
"animals": ["dog","cat","mouse"]
"fruits": ["orange","apple","banana"]
"trees": "["oak","pine"]

I would like to highlight dog, apple and pine in the Text field but those values come from multiple other fields (animals, fruits and trees in the example). Moreover i do not want to explicitly specify the strings "dog" "apple" and "pine" in any sort of highlight query. It would be great if the Text field is highlighted with any value that is also present in the animals, fruits or trees field.

Why do I need this? I do have documents containing a large text field and multiple other fields containing special terms that i would like to highlight, e.g. with different colors (pre/post tags).

Thank you very much for your help in advance.

Hi @crab86, this might work for you. :slight_smile:

Hi @miker256,

thanks for the reply but this is actually not what i try to achieve. In the article you referenced it is described how to highlight a query in multiple fields. What i would like to do is highlight all the values from multiple field in another field without specifying them in the query at all.

So in the above example if i would query for "eats" i would still like to have the highlights for "dog", "apple" and "pine" from 3 other fields being highlighted in the Text field.

If you know in advance these foods are found in this text then the “annotated_text” field format and corresponding highlighter may be of interest. https://www.elastic.co/blog/search-for-things-not-strings-with-the-annotated-text-plugin

Many thanks for mentioning this, i think it could help to solve this issue. However i do have millions of documents and i would then first need to parse them and add specific annotated markdown additions. And i do not think Logstash or Elasticsearch (via analyzer?) has anything to offer to automatically enrich documents in such a way?

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