elasticsearch/elasticsearch — pull request #2959 by tarass (2013-04-30 21:25:33+00:00)
Title: Alternate model for field AND logic within MultiMatch query

I wrote a patch to MultiMatch query that provides more natural and processing when considering multiple fields.

Consider document with fields:
title: Something
description: featured on their 1969 album Abbey Road
author: Beatles
Now if I take user's input and run a query to match my documents, it would be natural to consider ether the dreaded _all field or a multi_match query like:
multi_match:{"query":"Something Beatles", "fields":["title", "description", "author"], "operator":"and"}

Which would get transformed into a boolean query such as:
(+title:something +title:beatles) (+description:something +description:beatles) (+author:something +author: beatles)

There is no match for our document! From human input perspective often the most natural way to AND multi-field search is to ensure each term is matched somewhere across all fields such as:
+(title:something description:something author:something) +(title:beatles description:beatles author:beatles)

My patch does exactly that and it also accounts for use of multiple analyzers which may remove tokens from some fields (ex: The Beatles). If a token is skipped by an analyzer it will be turned into a should requirement on remaining fields instead of a must.

I am using facilities of match query for minimum should match as well as fuzzy processing so a new match type felt natural.
multi_match:{"query":"Something Beatles", "fields":["title", "description", "author"], "type":"across"}