# How can I tell what matched?

**URL:** https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214
**Category:** Elasticsearch
**Created:** [April 3, 2012, 5:47pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214 "2012-04-03T17:47:33Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rbrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rbrc/32/2937_2.png) [@rbrc](https://discuss.elastic.co/u/rbrc)
#### Post date: [April 3, 2012, 5:47pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/1 "2012-04-03T17:47:33Z")

</div>

If I have a document that has many fields and I do a generic search  
on, say, "foo", then I'd like to be able to highlight which field or  
fields matched "foo" so that I can highlight that for the user. So  
far it seems that my choices are to store the \_all field, which is  
unwise (and I can't seem to get it working), or to name every single  
field in the the highlight section of the query, which  
seems...inelegant, to say the least. Is there some other way of doing  
this?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 3, 2012, 7:02pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/2 "2012-04-03T19:02:18Z")

</div>

IMHO you will have to tell ES each field you want to highlight. Highlighting \_all can give strange results.

David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 3 avr. 2012 à 19:47, rbrc [wednesday@gmail.com](mailto:wednesday@gmail.com) a écrit :

> If I have a document that has many fields and I do a generic search  
> on, say, "foo", then I'd like to be able to highlight which field or  
> fields matched "foo" so that I can highlight that for the user. So  
> far it seems that my choices are to store the \_all field, which is  
> unwise (and I can't seem to get it working), or to name every single  
> field in the the highlight section of the query, which  
> seems...inelegant, to say the least. Is there some other way of doing  
> this?

---

<div class="post-metadata">

### Author: ![rbrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rbrc/32/2937_2.png) [@rbrc](https://discuss.elastic.co/u/rbrc)
#### Post date: [April 3, 2012, 7:44pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/3 "2012-04-03T19:44:24Z")

</div>

Any examples of that weirdness? Also I don't think that would work  
well for multi document type searches...

On Apr 3, 3:02 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> IMHO you will have to tell ES each field you want to highlight. Highlighting \_all can give strange results.
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr
> 
> Le 3 avr. 2012 à 19:47, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) a écrit :
> 
> > If I have a document that has many fields and I do a generic search  
> > on, say, "foo", then I'd like to be able to highlight which field or  
> > fields matched "foo" so that I can highlight that for the user. So  
> > far it seems that my choices are to store the \_all field, which is  
> > unwise (and I can't seem to get it working), or to name every single  
> > field in the the highlight section of the query, which  
> > seems...inelegant, to say the least. Is there some other way of doing  
> > this?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 3, 2012, 11:05pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/4 "2012-04-03T23:05:22Z")

</div>

If you have a type A and a type B with fields A.a and B.a and B.b, you can  
highlight "A.a" and "B.b" without highlighting "B.a". So you can "play" with  
types and highlights as you want.

Is it your use case ?

BTW, highlighting is working fine also with multifields :

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

David

> -----Message d'origine-----  
> De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de rbrc  
> Envoyé : mardi 3 avril 2012 21:44  
> À : elasticsearch  
> Objet : Re: how can I tell what matched?
> 
> Any examples of that weirdness? Also I don't think that would work  
> well for multi document type searches...
> 
> On Apr 3, 3:02 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > IMHO you will have to tell ES each field you want to highlight.  
> > Highlighting \_all can give strange results.
> > 
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr
> > 
> > Le 3 avr. 2012 à 19:47, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) a écrit :
> > 
> > > If I have a document that has many fields and I do a generic search  
> > > on, say, "foo", then I'd like to be able to highlight which field  
> > > or  
> > > fields matched "foo" so that I can highlight that for the user. So  
> > > far it seems that my choices are to store the \_all field, which is  
> > > unwise (and I can't seem to get it working), or to name every  
> > > single  
> > > field in the the highlight section of the query, which  
> > > seems...inelegant, to say the least. Is there some other way of  
> > > doing this?

---

<div class="post-metadata">

### Author: ![rbrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rbrc/32/2937_2.png) [@rbrc](https://discuss.elastic.co/u/rbrc)
#### Post date: [April 4, 2012, 1:56pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/5 "2012-04-04T13:56:43Z")

</div>

I'm not quite sure yet how many doctypes we will have, but I'd bet at  
least 3 and possibly as many as 10. In general, I'll want to search  
across at least 3 of these at any given time. Most documents will  
likely have an overlap of 2 fields, maybe 3.

On Apr 3, 7:05 pm, "David Pilato" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> If you have a type A and a type B with fields A.a and B.a and B.b, you can  
> highlight "A.a" and "B.b" without highlighting "B.a". So you can "play" with  
> types and highlights as you want.
> 
> Is it your use case ?
> 
> BTW, highlighting is working fine also with multifields :[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)...
> 
> David
> 
> > -----Message d'origine-----  
> > De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de rbrc  
> > Envoyé : mardi 3 avril 2012 21:44  
> > À : elasticsearch  
> > Objet : Re: how can I tell what matched?
> 
> > Any examples of that weirdness? Also I don't think that would work  
> > well for multi document type searches...
> 
> > On Apr 3, 3:02 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > IMHO you will have to tell ES each field you want to highlight.  
> > > Highlighting \_all can give strange results.
> 
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr
> 
> > > Le 3 avr. 2012 à 19:47, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) a écrit :
> 
> > > > If I have a document that has many fields and I do a generic search  
> > > > on, say, "foo", then I'd like to be able to highlight which field  
> > > > or  
> > > > fields matched "foo" so that I can highlight that for the user. So  
> > > > far it seems that my choices are to store the \_all field, which is  
> > > > unwise (and I can't seem to get it working), or to name every  
> > > > single  
> > > > field in the the highlight section of the query, which  
> > > > seems...inelegant, to say the least. Is there some other way of  
> > > > doing this?

---

<div class="post-metadata">

### Author: ![rbrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rbrc/32/2937_2.png) [@rbrc](https://discuss.elastic.co/u/rbrc)
#### Post date: [April 4, 2012, 2:40pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/6 "2012-04-04T14:40:56Z")

</div>

Thankfully I have schemas (via Mongoose as this is a nodejs/mongodb  
project) for all of the indexed documents so I can pull the highlight  
fields from those. I guess thats a workable solution.

On Apr 4, 9:56 am, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) wrote:

> I'm not quite sure yet how many doctypes we will have, but I'd bet at  
> least 3 and possibly as many as 10. In general, I'll want to search  
> across at least 3 of these at any given time. Most documents will  
> likely have an overlap of 2 fields, maybe 3.
> 
> On Apr 3, 7:05 pm, "David Pilato" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > If you have a type A and a type B with fields A.a and B.a and B.b, you can  
> > highlight "A.a" and "B.b" without highlighting "B.a". So you can "play" with  
> > types and highlights as you want.
> 
> > Is it your use case ?
> 
> > BTW, highlighting is working fine also with multifields :[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)...
> 
> > David
> 
> > > -----Message d'origine-----  
> > > De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > > [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de rbrc  
> > > Envoyé : mardi 3 avril 2012 21:44  
> > > À : elasticsearch  
> > > Objet : Re: how can I tell what matched?
> 
> > > Any examples of that weirdness? Also I don't think that would work  
> > > well for multi document type searches...
> 
> > > On Apr 3, 3:02 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > > 
> > > > IMHO you will have to tell ES each field you want to highlight.  
> > > > Highlighting \_all can give strange results.
> 
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr
> 
> > > > Le 3 avr. 2012 à 19:47, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) a écrit :
> 
> > > > > If I have a document that has many fields and I do a generic search  
> > > > > on, say, "foo", then I'd like to be able to highlight which field  
> > > > > or  
> > > > > fields matched "foo" so that I can highlight that for the user. So  
> > > > > far it seems that my choices are to store the \_all field, which is  
> > > > > unwise (and I can't seem to get it working), or to name every  
> > > > > single  
> > > > > field in the the highlight section of the query, which  
> > > > > seems...inelegant, to say the least. Is there some other way of  
> > > > > doing this?

---

<div class="post-metadata">

### Author: ![rbrc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rbrc/32/2937_2.png) [@rbrc](https://discuss.elastic.co/u/rbrc)
#### Post date: [April 4, 2012, 2:41pm UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/7 "2012-04-04T14:41:53Z")

</div>

And thank you for the help. 🙂

On Apr 4, 10:40 am, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) wrote:

> Thankfully I have schemas (via Mongoose as this is a nodejs/mongodb  
> project) for all of the indexed documents so I can pull the highlight  
> fields from those. I guess thats a workable solution.
> 
> On Apr 4, 9:56 am, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) wrote:
> 
> > I'm not quite sure yet how many doctypes we will have, but I'd bet at  
> > least 3 and possibly as many as 10. In general, I'll want to search  
> > across at least 3 of these at any given time. Most documents will  
> > likely have an overlap of 2 fields, maybe 3.
> 
> > On Apr 3, 7:05 pm, "David Pilato" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > > If you have a type A and a type B with fields A.a and B.a and B.b, you can  
> > > highlight "A.a" and "B.b" without highlighting "B.a". So you can "play" with  
> > > types and highlights as you want.
> 
> > > Is it your use case ?
> 
> > > BTW, highlighting is working fine also with multifields :[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)...
> 
> > > David
> 
> > > > -----Message d'origine-----  
> > > > De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> > > > [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de rbrc  
> > > > Envoyé : mardi 3 avril 2012 21:44  
> > > > À : elasticsearch  
> > > > Objet : Re: how can I tell what matched?
> 
> > > > Any examples of that weirdness? Also I don't think that would work  
> > > > well for multi document type searches...
> 
> > > > On Apr 3, 3:02 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > > > 
> > > > > IMHO you will have to tell ES each field you want to highlight.  
> > > > > Highlighting \_all can give strange results.
> 
> > > > > David 😉  
> > > > > Twitter : @dadoonet / @elasticsearchfr
> 
> > > > > Le 3 avr. 2012 à 19:47, rbrc [wednes...@gmail.com](mailto:wednes...@gmail.com) a écrit :
> 
> > > > > > If I have a document that has many fields and I do a generic search  
> > > > > > on, say, "foo", then I'd like to be able to highlight which field  
> > > > > > or  
> > > > > > fields matched "foo" so that I can highlight that for the user. So  
> > > > > > far it seems that my choices are to store the \_all field, which is  
> > > > > > unwise (and I can't seem to get it working), or to name every  
> > > > > > single  
> > > > > > field in the the highlight section of the query, which  
> > > > > > seems...inelegant, to say the least. Is there some other way of  
> > > > > > doing this?

---

<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, 3:33am UTC](https://discuss.elastic.co/t/how-can-i-tell-what-matched/7214/8 "2017-07-06T03:33:40Z")

</div>


