Searching multiple fields with different analyzers using Query String Query


(Patrick Lam) #1

Hi,

Suppose I have two fields in my index: "text" and "tag". The "text" field uses one analyzer (standard) and the "tag" field is not analyzed.

Now I suppose I need to do an OR query across both fields and I MUST use the Query String Query. For example, I want to match any document that contains either "quick AND brown" in the text field or "tweets" in the tag field. For the query in the text field, I want the search string to be analyzed in the same way as the text field (standard) and for the query on the tag field, I want it to match the analyzer in the tag field (not analyzed).

According to the documentation on Query String Query, I can do something like this:

Set the default_field to "text", analyzer to standard, and then search using the string "quick AND brown OR tag:tweets". However, this seems to automatically analyze the whole search string such that the word "tweets" also gets analyzed using the standard analyzer, which means that it no longer correctly matches the tag field.

I know this is much easier using a Boolean query, but is there a way to make this work in Query String Query such that I can do an OR search across multiple fields where the respective search strings match the analyzer of the field itself?


(system) #2