6
votes

Is it possible to use a minimum_should_match on a phrase query? Eg "quick brown dog" could match "I have a quick dog" and score higher than "dogs run around but the cat is quick" assuming a high enough slop and a minimum match of "2".

I can't find any examples of this. If a phrase match cannot do it, is there another way to accomplish this?

1
just tried it and it seems it's not supported. So really the question is how to accomplish this in another way.Yehosef

1 Answers

1
votes

I saw there were upvotes for this question so I'll post how I approached it. I took the phrase "quick brown dog" (#1) and split it into three new phrases "quick brown"(#2) "quick dog" (#3) and "brown dog" (#4) and applied a these three along with the original as parts of a bool query (each was a "should" clause").

The first example document I gave I have a quick dog would match only #3 and the second document would not match any of them. Therefore the first document would match, which is what I was after.

In this example there I wanted a minimum word match of 2 - if you needed more you would create larger shingles.

FYI - I think this might also be possible using a shingle token filter (https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-shingle-tokenfilter.html) on the search. See Elastic search- search_analyzer vs index_analyzer for more info. I didn't try this and I'm not sure if it works with the phrase queries and slop - but it would be great if it does.