# How to know which field (fields) is matched and do the custom highlighting?

**URL:** https://discuss.elastic.co/t/how-to-know-which-field-fields-is-matched-and-do-the-custom-highlighting/3514
**Category:** Elasticsearch
**Created:** [November 4, 2010, 1:30am UTC](https://discuss.elastic.co/t/how-to-know-which-field-fields-is-matched-and-do-the-custom-highlighting/3514 "2010-11-04T01:30:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chunlei\_Wu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chunlei_wu/32/824_2.png) [@Chunlei\_Wu](https://discuss.elastic.co/u/Chunlei_Wu)
#### Post date: [November 4, 2010, 1:30am UTC](https://discuss.elastic.co/t/how-to-know-which-field-fields-is-matched-and-do-the-custom-highlighting/3514/1 "2010-11-04T01:30:17Z")

</div>

Hi,

```
 My JSON document to be indexed has dozens of fields:

```

{  
"field1": "foo",  
"field2": ["bar1", "bar2", "bar3"],  
"field3": ["foo", "foo2"],  
"field4": "adskj akfjoa asdfja foo adbja ...",  
... ...  
}

I can index them in ES without a problem. My query is mostly looking  
for matches on any fields (e.g., just a string query of "foo").

My question is to know which fields are matched (like "field1",  
"field3" and "field4" for a query of "foo")? I can pass all my fields  
for highlighting, and that will return matched fields with highlighted  
snippets and the rest of fields with "[]". Because I have large amount  
of fields, that will make the returned query result quite big. So I am  
wondering if there is other better way to do that or any way to simply  
remove the unmatched fields from "highlight".

My eventual purpose is to get a custom highlighting like this (for a  
query "foo"):

{  
...  
"highlight": {"field1": ["_foo_"],  
"field3": ["_foo_, foo2"],  
"field4": ["adskj akfjoa asdfja _foo_  
adbja"],  
},  
...  
}

Basically, for a field with an array of values (i.e., "field3"), I  
need to highlight matches under the context of other values.

Thanks a lot.

Chunlei

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 4:17am UTC](https://discuss.elastic.co/t/how-to-know-which-field-fields-is-matched-and-do-the-custom-highlighting/3514/2 "2017-07-06T04:17:12Z")

</div>


