Right way to switch analyzers mid query


(Nik Everett) #1

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.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #2