MultiPhraseQuery in Elastic using NEST


(Omri Suissa) #1

Hi,
I'm migrating from Lucene to Elastic (6.2.4).

Today we use Lucene's MultiPhraseQuery to set phrase queries in the same position. Elastic (and NEST) comes with a "MatchPhrase" query that can get only one phrase (string). There is an equivalent to MultiPhraseQuery as well?


(Russ Cam) #2

It looks like Lucene's MultiPhraseQuery maps to Elasticsearch's Match Phrase Prefix query, with prefix matches on the last term.


(Omri Suissa) #3

@forloop, thank you for your response.
I don't think MultiPhraseQuery (lucene) is equivalent to Match Phrase Prefix query (elastic).

MultiPhraseQuery is "A generalized version of PhraseQuery, with the possibility of adding more than one term at the same position that are treated as a disjunction (OR)."

While Match Phrase Prefix query is "The match_phrase_prefix is the same as match_phrase, except that it allows for prefix matches on the last term in the text"

It is true that you can use both for some functionality, but it is not the same.
The main feature for MultiPhraseQuery is the fact that both terms are in the same position.

Thanks


(Russ Cam) #4

Gotcha!

It looks like MultiPhrseQuery is not exposed in the REST API of Elasticsearch; it's used internally in a few places but no exposed.

You should however be able to achieve similar functionality with span_near and nested span_or queries


(Omri Suissa) #5

Thank you. span or is similar but with some main differences:
1 - Performance is not as fast as MultiPhrseQuery
2 - it calculates scoring differently (not dismax, but sum like bool query)

There is a way to expose it in the next version or with a patch?
This is a powerful MultiPhrseQuery type in lucene.

Thanks!


(Russ Cam) #6

I would recommend opening a new issue on the Elasticsearch repository first to discuss with folks from Elasticsearch core team.


(Omri Suissa) #7

Thank you!