# Right way to switch analyzers mid query

**URL:** <https://discuss.elastic.co/t/right-way-to-switch-analyzers-mid-query/13683>\
**Category:** Elasticsearch\
**Created:** [September 19, 2013, 12:13am UTC](https://discuss.elastic.co/t/right-way-to-switch-analyzers-mid-query/13683 "2013-09-19T00:13:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 19, 2013, 12:13am UTC](https://discuss.elastic.co/t/right-way-to-switch-analyzers-mid-query/13683/1 "2013-09-19T00:13:30Z")

</div>

Say I have a query like:  
"query\_string": {  
"query": "Santa loves grapes",  
"fields": ["a", "b"]  
}

but I want "grapes" to use a different analyzer than "Santa loves". I  
think I have two options:  
"bool": {  
"minimum\_should\_match": 2,  
"should": [ {  
"query\_string": {  
"query": "Santa loves",  
"fields": ["a", "b"],  
"analyzer": "normal"  
}, {  
"query\_string": {  
"query": "grapes",  
"fields": ["a", "b"],  
"analyzer": "other"  
}  
} ]  
}

or:  
"query\_string": {  
"query": "Santa loves (a.other:grapes OR b.other:grapes)",  
"fields": ["a", "b"],  
"analyzer": "normal"  
}

The second option is pretty simple to write and requires that a and b be  
multifields who'se default field is analyzed by "normal" and have an  
"other" field analyzed by the "other" analyzer.

The first option requires that a and b be analyzed by both analyzers which  
I'm sure is possible but I don't know the syntax for and might have some  
unexpected side effects.

But so far as I can tell, the only way to get highlighting to highlight all  
the terms together is with the first option. Am I stuck with the first  
option if I want highlighting? Is it better for reasons other than  
highlighting?

Thanks for reading all this,

Nik

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:15am UTC](https://discuss.elastic.co/t/right-way-to-switch-analyzers-mid-query/13683/2 "2017-07-06T02:15:37Z")

</div>

Closed on July 6, 2017, 2:15am UTC


