# What analyzer does query\_string use for highlighting?

**URL:** <https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027>\
**Category:** Elasticsearch\
**Created:** [November 30, 2011, 2:14pm UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027 "2011-11-30T14:14:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Weiwei\_Wang](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@Weiwei\_Wang](https://discuss.elastic.co/u/Weiwei_Wang)\
**Post date:** [November 30, 2011, 2:14pm UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027/1 "2011-11-30T14:14:42Z")

</div>

I have mutiple-fields for search, but each field with different  
search\_analyzer. when do highlighting i found that the fragments is  
not as expected.

for example, i have two fields: name, phone, and i have two analyzers  
in my elasticsearch.json  
"analysis" : {  
"analyzer" : {  
"nGramAnalyzer":{  
"type":"custom",  
"tokenizer":"standard",  
"filter":  
["standard","lowercase","englishSnowball","nGramFilter"]  
},  
"standardAnalyzer":{  
"type":"custom",  
"tokenizer":"standard",  
"filter":  
["standard","lowercase","englishSnowball"]  
}  
},  
"filter":{  
"nGramFilter":{  
"type":"nGram",  
"min\_gram":1,  
"max\_gram":64  
},  
"edgeNGramFilter":{  
"type":"edgeNGram",  
"min\_gram":1,  
"max\_gram":64,  
"side":"front"  
},  
"englishSnowball":{  
"type":"snowball",  
"language":"English"  
}  
}

the mapping for the fields are:  
"phone":{  
"type" : "string",  
"index": "analyzed",  
"index\_analyzer":"nGramAnalyzer",  
"search\_analyzer":"nGramAnalyzer",  
"store":"yes",  
"term\_vector":"with\_positions\_offsets"  
},  
"phone":{  
"type" : "string",  
"index": "analyzed",  
"index\_analyzer":"nGramAnalyzer",  
"search\_analyzer":"standardAnalyzer",  
"store":"yes",  
"term\_vector":"with\_positions\_offsets"  
}

when i do query\_string query like below:  
curl '10.18.102.101:9201/pim/contact/\_search?pretty=true' -d '{"from":  
0,"size":2,"query":{"query\_string":{"query":"18600","fields":  
["name^5.0","phone^5.0"],"default\_operator":"or","allow\_leading\_wildcard":false,"analyze\_wildcard":true}},"filter":  
{"bool":{"must":{"term":{"deleted":0}}}},"explain":false,"fields":  
["name", "phone"],"highlight":{"pre\_tags":["\<span class="hl  
"\>"],"post\_tags":[""],"fields":{"name":{},"phone":{}}}}'

the highlight is show as:  
_1 __8__ 6 __0__ 0__0_4422_0\</  
em\>_

it seems the highlighter uses the nGramAnalyzer for highlighting, but  
i expect it use the relevant search\_analyzer to do hightlighting for  
the field

any one do me a favor for this problem?

elasticsearch version 0.18.4

---

<div class="post-metadata">

**Author:** ![Goog\_Jobs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/goog_jobs/32/2894_2.png) [@Goog\_Jobs](https://discuss.elastic.co/u/Goog_Jobs)\
**Post date:** [December 1, 2011, 10:54am UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027/2 "2011-12-01T10:54:52Z")

</div>

two mappings for the same filed? the lucene demands index\_analyzer to  
be same with "search\_analyzer". 希望有用。

On Nov 30, 10:14 pm, Weiwei Wang [ww.wang...@gmail.com](mailto:ww.wang...@gmail.com) wrote:

> I have mutiple-fields for search, but each field with different  
> search\_analyzer. when do highlighting i found that the fragments is  
> not as expected.
> 
> for example, i have two fields: name, phone, and i have two analyzers  
> in my elasticsearch.json  
> "analysis" : {  
> "analyzer" : {  
> "nGramAnalyzer":{  
> "type":"custom",  
> "tokenizer":"standard",  
> "filter":  
> ["standard","lowercase","englishSnowball","nGramFilter"]  
> },  
> "standardAnalyzer":{  
> "type":"custom",  
> "tokenizer":"standard",  
> "filter":  
> ["standard","lowercase","englishSnowball"]  
> }  
> },  
> "filter":{  
> "nGramFilter":{  
> "type":"nGram",  
> "min\_gram":1,  
> "max\_gram":64  
> },  
> "edgeNGramFilter":{  
> "type":"edgeNGram",  
> "min\_gram":1,  
> "max\_gram":64,  
> "side":"front"  
> },  
> "englishSnowball":{  
> "type":"snowball",  
> "language":"English"  
> }  
> }
> 
> the mapping for the fields are:  
> "phone":{  
> "type" : "string",  
> "index": "analyzed",  
> "index\_analyzer":"nGramAnalyzer",  
> "search\_analyzer":"nGramAnalyzer",  
> "store":"yes",  
> "term\_vector":"with\_positions\_offsets"  
> },  
> "phone":{  
> "type" : "string",  
> "index": "analyzed",  
> "index\_analyzer":"nGramAnalyzer",  
> "search\_analyzer":"standardAnalyzer",  
> "store":"yes",  
> "term\_vector":"with\_positions\_offsets"  
> }
> 
> when i do query\_string query like below:  
> curl '10.18.102.101:9201/pim/contact/\_search?pretty=true' -d '{"from":  
> 0,"size":2,"query":{"query\_string":{"query":"18600","fields":  
> ["name^5.0","phone^5.0"],"default\_operator":"or","allow\_leading\_wildcard":f alse,"analyze\_wildcard":true}},"filter":  
> {"bool":{"must":{"term":{"deleted":0}}}},"explain":false,"fields":  
> ["name", "phone"],"highlight":{"pre\_tags":["\<span class="hl  
> "\>"],"post\_tags":[""],"fields":{"name":{},"phone":{}}}}'
> 
> the highlight is show as:  
> _1 __8__ 6 __0__ 0__0_4422_0\</  
> em\>_
> 
>  
> 
> _it seems the highlighter uses the nGramAnalyzer for highlighting, but  
> i expect it use the relevant search\_analyzer to do hightlighting for  
> the field_
> 
>  
> 
> _any one do me a favor for this problem?_
> 
>  
> 
> _elasticsearch version 0.18.4_

---

<div class="post-metadata">

**Author:** ![medcl\_net](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@medcl\_net](https://discuss.elastic.co/u/medcl_net)\
**Post date:** [December 2, 2011, 10:33am UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027/3 "2011-12-02T10:33:09Z")

</div>

because the the term positions AND offsets are generated and stored during  
indexing , not the searching~

-----Original Message-----  
From: Weiwei Wang  
Sent: Wednesday, November 30, 2011 10:14 PM  
To: elasticsearch  
Subject: what analyzer does query\_string use for highlighting?

I have mutiple-fields for search, but each field with different  
search\_analyzer. when do highlighting i found that the fragments is  
not as expected.

for example, i have two fields: name, phone, and i have two analyzers  
in my elasticsearch.json  
"analysis" : {  
"analyzer" : {  
"nGramAnalyzer":{  
"type":"custom",  
"tokenizer":"standard",  
"filter":  
["standard","lowercase","englishSnowball","nGramFilter"]  
},  
"standardAnalyzer":{  
"type":"custom",  
"tokenizer":"standard",  
"filter":  
["standard","lowercase","englishSnowball"]  
}  
},  
"filter":{  
"nGramFilter":{  
"type":"nGram",  
"min\_gram":1,  
"max\_gram":64  
},  
"edgeNGramFilter":{  
"type":"edgeNGram",  
"min\_gram":1,  
"max\_gram":64,  
"side":"front"  
},  
"englishSnowball":{  
"type":"snowball",  
"language":"English"  
}  
}

the mapping for the fields are:  
"phone":{  
"type" : "string",  
"index": "analyzed",  
"index\_analyzer":"nGramAnalyzer",  
"search\_analyzer":"nGramAnalyzer",  
"store":"yes",  
"term\_vector":"with\_positions\_offsets"  
},  
"phone":{  
"type" : "string",  
"index": "analyzed",  
"index\_analyzer":"nGramAnalyzer",  
"search\_analyzer":"standardAnalyzer",  
"store":"yes",  
"term\_vector":"with\_positions\_offsets"  
}

when i do query\_string query like below:  
curl '10.18.102.101:9201/pim/contact/\_search?pretty=true' -d '{"from":  
0,"size":2,"query":{"query\_string":{"query":"18600","fields":  
["name^5.0","phone^5.0"],"default\_operator":"or","allow\_leading\_wildcard":false,"analyze\_wildcard":true}},"filter":  
{"bool":{"must":{"term":{"deleted":0}}}},"explain":false,"fields":  
["name", "phone"],"highlight":{"pre\_tags":["\<span class="hl  
"\>"],"post\_tags":[""],"fields":{"name":{},"phone":{}}}}'

the highlight is show as:  
_1 __8__ 6 __0__ 0__0_4422_0\</  
em\>_

it seems the highlighter uses the nGramAnalyzer for highlighting, but  
i expect it use the relevant search\_analyzer to do hightlighting for  
the field

any one do me a favor for this problem?

elasticsearch version 0.18.4

---

<div class="post-metadata">

**Author:** ![Weiwei\_Wang](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@Weiwei\_Wang](https://discuss.elastic.co/u/Weiwei_Wang)\
**Post date:** [December 7, 2011, 5:54am UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027/4 "2011-12-07T05:54:34Z")

</div>

thanks, but when i disable term\_vector, everything will be ok

On Dec 2, 6:33 pm, [medcl2...@gmail.com](mailto:medcl2...@gmail.com) wrote:

> because the the term positions AND offsets are generated and stored during  
> indexing , not the searching~
> 
> -----Original Message-----  
> From:WeiweiWang  
> Sent: Wednesday, November 30, 2011 10:14 PM  
> To: elasticsearch  
> Subject: what analyzer does query\_string use for highlighting?
> 
> I have mutiple-fields for search, but each field with different  
> search\_analyzer. when do highlighting i found that the fragments is  
> not as expected.
> 
> for example, i have two fields: name, phone, and i have two analyzers  
> in my elasticsearch.json  
> "analysis" : {  
> "analyzer" : {  
> "nGramAnalyzer":{  
> "type":"custom",  
> "tokenizer":"standard",  
> "filter":  
> ["standard","lowercase","englishSnowball","nGramFilter"]  
> },  
> "standardAnalyzer":{  
> "type":"custom",  
> "tokenizer":"standard",  
> "filter":  
> ["standard","lowercase","englishSnowball"]  
> }  
> },  
> "filter":{  
> "nGramFilter":{  
> "type":"nGram",  
> "min\_gram":1,  
> "max\_gram":64  
> },  
> "edgeNGramFilter":{  
> "type":"edgeNGram",  
> "min\_gram":1,  
> "max\_gram":64,  
> "side":"front"  
> },  
> "englishSnowball":{  
> "type":"snowball",  
> "language":"English"  
> }  
> }
> 
> the mapping for the fields are:  
> "phone":{  
> "type" : "string",  
> "index": "analyzed",  
> "index\_analyzer":"nGramAnalyzer",  
> "search\_analyzer":"nGramAnalyzer",  
> "store":"yes",  
> "term\_vector":"with\_positions\_offsets"  
> },  
> "phone":{  
> "type" : "string",  
> "index": "analyzed",  
> "index\_analyzer":"nGramAnalyzer",  
> "search\_analyzer":"standardAnalyzer",  
> "store":"yes",  
> "term\_vector":"with\_positions\_offsets"  
> }
> 
> when i do query\_string query like below:  
> curl '10.18.102.101:9201/pim/contact/\_search?pretty=true' -d '{"from":  
> 0,"size":2,"query":{"query\_string":{"query":"18600","fields":  
> ["name^5.0","phone^5.0"],"default\_operator":"or","allow\_leading\_wildcard":f alse,"analyze\_wildcard":true}},"filter":  
> {"bool":{"must":{"term":{"deleted":0}}}},"explain":false,"fields":  
> ["name", "phone"],"highlight":{"pre\_tags":["\<span class="hl  
> "\>"],"post\_tags":[""],"fields":{"name":{},"phone":{}}}}'
> 
> the highlight is show as:  
> _1 __8__ 6 __0__ 0__0_4422_0\</  
> em\>_
> 
>  
> 
> _it seems the highlighter uses the nGramAnalyzer for highlighting, but  
> i expect it use the relevant search\_analyzer to do hightlighting for  
> the field_
> 
>  
> 
> _any one do me a favor for this problem?_
> 
>  
> 
> _elasticsearch version 0.18.4_

---

<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:46am UTC](https://discuss.elastic.co/t/what-analyzer-does-query-string-use-for-highlighting/6027/5 "2017-07-06T03:46:15Z")

</div>


