# Highlighting highlights all words in all fields when searching for field:\*

**URL:** <https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777>\
**Category:** Elasticsearch\
**Created:** [August 18, 2012, 6:06am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777 "2012-08-18T06:06:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Waddle\_2](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mark\_Waddle\_2](https://discuss.elastic.co/u/Mark_Waddle_2)\
**Post date:** [August 18, 2012, 6:06am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/1 "2012-08-18T06:06:16Z")

</div>

When I execute a search with a query like "field:\*", and specify a number  
of fields to be highlighted, it seems to highlight all words, except stop  
words, for all of those fields. It doesn't matter whether the field  
searched on is in the highlighted field set or not. This seems incorrect to  
me. It seems like only the words in the field specified in the query should  
be highlighted, and only if that field is included in the highlighted field  
set of course. Am I doing something wrong? Are my expectations wrong? Is  
this a bug?

Thanks,  
Mark

--

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [August 18, 2012, 6:10am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/2 "2012-08-18T06:10:28Z")

</div>

Hi,

do you think you can prepare recreation script?

Regards,  
Lukas  
Dne 18.8.2012 8:06 "Mark Waddle" [mark@redfoleo.com](mailto:mark@redfoleo.com) napsal(a):

> When I execute a search with a query like "field:\*", and specify a number  
> of fields to be highlighted, it seems to highlight all words, except stop  
> words, for all of those fields. It doesn't matter whether the field  
> searched on is in the highlighted field set or not. This seems incorrect to  
> me. It seems like only the words in the field specified in the query should  
> be highlighted, and only if that field is included in the highlighted field  
> set of course. Am I doing something wrong? Are my expectations wrong? Is  
> this a bug?
> 
> Thanks,  
> Mark
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle\_2](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mark\_Waddle\_2](https://discuss.elastic.co/u/Mark_Waddle_2)\
**Post date:** [August 18, 2012, 6:25am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/3 "2012-08-18T06:25:18Z")

</div>

#!/bin/bash  
curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
echo  
curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
echo  
curl -XPUT -d '{  
"doc" : {  
"\_source" : { "enabled" : false },  
"\_all" : { "enabled" : true },  
"\_timestamp" : { "enabled" : true, "store" : "yes" },  
"properties" : {  
"text1" : {  
"type" : "string",  
"store" : "yes"  
},  
"text2" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
echo  
curl -XPOST -d '{ "text1": "doc1 and text1", "text2": "doc1 and text2" }'  
[http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
echo  
curl -XPOST -d '{ "text1": "doc2 and text1", "text2": "doc2 and text2" }'  
[http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
echo  
curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
echo  
curl -d '{ "query" : { "query\_string" : { "query" : "text1:\*" } }, "fields"  
: ["text1", "text2"], "highlight" : { "fields" : { "text1" : {}, "text2" :  
{} } } }' [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true)  
echo

On Friday, August 17, 2012 11:10:28 PM UTC-7, Lukáš Vlček wrote:

> Hi,
> 
> do you think you can prepare recreation script?
> 
> Regards,  
> Lukas  
> Dne 18.8.2012 8:06 "Mark Waddle" \<[ma...@redfoleo.com](mailto:ma...@redfoleo.com) \<javascript:\>\>  
> napsal(a):
> 
> > When I execute a search with a query like "field:\*", and specify a number  
> > of fields to be highlighted, it seems to highlight all words, except stop  
> > words, for all of those fields. It doesn't matter whether the field  
> > searched on is in the highlighted field set or not. This seems incorrect to  
> > me. It seems like only the words in the field specified in the query should  
> > be highlighted, and only if that field is included in the highlighted field  
> > set of course. Am I doing something wrong? Are my expectations wrong? Is  
> > this a bug?
> > 
> > Thanks,  
> > Mark
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle\_2](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mark\_Waddle\_2](https://discuss.elastic.co/u/Mark_Waddle_2)\
**Post date:** [August 19, 2012, 10:27pm UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/4 "2012-08-19T22:27:52Z")

</div>

Has anyone been able to reproduce this with the script?

On Friday, August 17, 2012 11:25:18 PM UTC-7, Mark Waddle wrote:

> #!/bin/bash  
> curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> echo  
> curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> echo  
> curl -XPUT -d '{  
> "doc" : {  
> "\_source" : { "enabled" : false },  
> "\_all" : { "enabled" : true },  
> "\_timestamp" : { "enabled" : true, "store" : "yes" },  
> "properties" : {  
> "text1" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "text2" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> }  
> }' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
> echo  
> curl -XPOST -d '{ "text1": "doc1 and text1", "text2": "doc1 and text2" }'  
> [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> echo  
> curl -XPOST -d '{ "text1": "doc2 and text1", "text2": "doc2 and text2" }'  
> [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> echo  
> curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
> echo  
> curl -d '{ "query" : { "query\_string" : { "query" : "text1:\*" } },  
> "fields" : ["text1", "text2"], "highlight" : { "fields" : { "text1" : {},  
> "text2" : {} } } }' [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true)  
> echo
> 
> On Friday, August 17, 2012 11:10:28 PM UTC-7, Lukáš Vlček wrote:
> 
> > Hi,
> > 
> > do you think you can prepare recreation script?
> > 
> > Regards,  
> > Lukas  
> > Dne 18.8.2012 8:06 "Mark Waddle" [ma...@redfoleo.com](mailto:ma...@redfoleo.com) napsal(a):
> > 
> > > When I execute a search with a query like "field:\*", and specify a  
> > > number of fields to be highlighted, it seems to highlight all words, except  
> > > stop words, for all of those fields. It doesn't matter whether the field  
> > > searched on is in the highlighted field set or not. This seems incorrect to  
> > > me. It seems like only the words in the field specified in the query should  
> > > be highlighted, and only if that field is included in the highlighted field  
> > > set of course. Am I doing something wrong? Are my expectations wrong? Is  
> > > this a bug?
> > > 
> > > Thanks,  
> > > Mark
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![Shaun\_Etherton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_etherton/32/2540_2.png) [@Shaun\_Etherton](https://discuss.elastic.co/u/Shaun_Etherton)\
**Post date:** [August 20, 2012, 2:18am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/5 "2012-08-20T02:18:57Z")

</div>

Hi

It seems ok to me.

This is the result i get running your script. I'm using elasticsearch-0.19.4.  
[https://gist.github.com/3399280](https://gist.github.com/3399280)

I'd say the query and the highlight are separate things and treating them separately is correct i.e.) the results are correct/expected.  
I ran the script as it was & then ran the query again with the text2 field removed from the highlight section and it behaves as i'd expect.

HTH.

cheers

On Monday, 20 August 2012 at 7:57 AM, Mark Waddle wrote:

> Has anyone been able to reproduce this with the script?
> 
> On Friday, August 17, 2012 11:25:18 PM UTC-7, Mark Waddle wrote:
> 
> > #!/bin/bash  
> > curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> > echo  
> > curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> > echo  
> > curl -XPUT -d '{  
> > "doc" : {  
> > "\_source" : { "enabled" : false },  
> > "\_all" : { "enabled" : true },  
> > "\_timestamp" : { "enabled" : true, "store" : "yes" },  
> > "properties" : {  
> > "text1" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "text2" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > }  
> > }  
> > }  
> > }' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
> > echo  
> > curl -XPOST -d '{ "text1": "doc1 and text1", "text2": "doc1 and text2" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > echo  
> > curl -XPOST -d '{ "text1": "doc2 and text1", "text2": "doc2 and text2" }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > echo  
> > curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
> > echo  
> > curl -d '{ "query" : { "query\_string" : { "query" : "text1:\*" } }, "fields" : ["text1", "text2"], "highlight" : { "fields" : { "text1" : {}, "text2" : {} } } }' [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true)  
> > echo
> > 
> > On Friday, August 17, 2012 11:10:28 PM UTC-7, Lukáš Vlček wrote:
> > 
> > > Hi,  
> > > do you think you can prepare recreation script?  
> > > Regards,  
> > > Lukas  
> > > Dne 18.8.2012 8:06 "Mark Waddle" [ma...@redfoleo.com](mailto:ma...@redfoleo.com) napsal(a):
> > > 
> > > > When I execute a search with a query like "field:\*", and specify a number of fields to be highlighted, it seems to highlight all words, except stop words, for all of those fields. It doesn't matter whether the field searched on is in the highlighted field set or not. This seems incorrect to me. It seems like only the words in the field specified in the query should be highlighted, and only if that field is included in the highlighted field set of course. Am I doing something wrong? Are my expectations wrong? Is this a bug?
> > > > 
> > > > ## Thanks, Mark
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle\_2](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Mark\_Waddle\_2](https://discuss.elastic.co/u/Mark_Waddle_2)\
**Post date:** [August 23, 2012, 6:48am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/6 "2012-08-23T06:48:46Z")

</div>

Thank you Shaun for trying it out. I am glad to see that you got the same  
results as me, but our expectations are different. I expected that even  
though I asked for highlighting on both term1 and term2, that it would only  
highlight term1 because the query match was limited to term1 (term1:\*).

However now that I think about it, this happens with any type of query,  
whether it is a wildcard or not. For example, if I execute a query of  
title:wireless, and request highlighting on the title and abstract field,  
it will highlight the word wireless in both. It is just especially heinous  
when doing a wildcard search because it highlights all terms in all  
highlighted fields. I guess it is because the highlighter is not aware of  
which field(s) the query actually hit on, and just highlights the search  
term in all fields where highlighting is requested.

I think I will open an enhancement issue.

On Sunday, August 19, 2012 7:18:57 PM UTC-7, Shaun Etherton wrote:

> Hi
> 
> It seems ok to me.
> 
> This is the result i get running your script. I'm using  
> elasticsearch-0.19.4.  
> [https://gist.github.com/3399280](https://gist.github.com/3399280)
> 
> I'd say the query and the highlight are separate things and treating them  
> separately is correct i.e.) the results are correct/expected.  
> I ran the script as it was & then ran the query again with the text2 field  
> removed from the highlight section and it behaves as i'd expect.
> 
> HTH.
> 
> cheers
> 
> On Monday, 20 August 2012 at 7:57 AM, Mark Waddle wrote:
> 
> > Has anyone been able to reproduce this with the script?
> > 
> > On Friday, August 17, 2012 11:25:18 PM UTC-7, Mark Waddle wrote:
> > 
> > > #!/bin/bash  
> > > curl -XDELETE '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> > > echo  
> > > curl -XPOST '[http://localhost:9200/highlight](http://localhost:9200/highlight)'  
> > > echo  
> > > curl -XPUT -d '{  
> > > "doc" : {  
> > > "\_source" : { "enabled" : false },  
> > > "\_all" : { "enabled" : true },  
> > > "\_timestamp" : { "enabled" : true, "store" : "yes" },  
> > > "properties" : {  
> > > "text1" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "text2" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > }  
> > > }  
> > > }  
> > > }' [http://localhost:9200/highlight/doc/\_mapping](http://localhost:9200/highlight/doc/_mapping)  
> > > echo  
> > > curl -XPOST -d '{ "text1": "doc1 and text1", "text2": "doc1 and text2"  
> > > }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > > echo  
> > > curl -XPOST -d '{ "text1": "doc2 and text1", "text2": "doc2 and text2"  
> > > }' [http://localhost:9200/highlight/doc](http://localhost:9200/highlight/doc)  
> > > echo  
> > > curl -XPOST [http://localhost:9200/highlight/\_refresh](http://localhost:9200/highlight/_refresh)  
> > > echo  
> > > curl -d '{ "query" : { "query\_string" : { "query" : "text1:\*" } },  
> > > "fields" : ["text1", "text2"], "highlight" : { "fields" : { "text1" : {},  
> > > "text2" : {} } } }' [http://localhost:9200/highlight/\_search?pretty=true](http://localhost:9200/highlight/_search?pretty=true)  
> > > echo
> > > 
> > > On Friday, August 17, 2012 11:10:28 PM UTC-7, Lukáš Vlček wrote:
> > > 
> > > > Hi,  
> > > > do you think you can prepare recreation script?  
> > > > Regards,  
> > > > Lukas  
> > > > Dne 18.8.2012 8:06 "Mark Waddle" [ma...@redfoleo.com](mailto:ma...@redfoleo.com) napsal(a):
> > > > 
> > > > > When I execute a search with a query like "field:\*", and specify a  
> > > > > number of fields to be highlighted, it seems to highlight all words, except  
> > > > > stop words, for all of those fields. It doesn't matter whether the field  
> > > > > searched on is in the highlighted field set or not. This seems incorrect to  
> > > > > me. It seems like only the words in the field specified in the query should  
> > > > > be highlighted, and only if that field is included in the highlighted field  
> > > > > set of course. Am I doing something wrong? Are my expectations wrong? Is  
> > > > > this a bug?
> > > > > 
> > > > > ## Thanks, Mark
> > 
> > --

--

---

<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:15am UTC](https://discuss.elastic.co/t/highlighting-highlights-all-words-in-all-fields-when-searching-for-field/8777/7 "2017-07-06T03:15:23Z")

</div>


