Partial phrase or exact phrase matching

Hi there,

I am new to elasticsearch and I want to search for a phrase.
Suppose I query with this phrase :

i am new to elasticsearch

And I have some data like
new to elasticsearch

I have tried with match_phrase but it won't return the document.

For exact matches you will need a term query https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html.

My main issue here is that if I have i am new to elasticsearch as data and I query with new to elasticsearch, it works but not vice versa

What does your query look like? What does your mapping look like?

I just have a simple mapping

{
  "mappings": {
      "properties": {
        "sentence": { "type": "text" }
      }
    }
}

And I query like this :

{
  "query": {
    "match_phrase": {
      "sentence": {
        "query": "i am new to elasticsearch"
      }
    }
  }
}

Hmm, I dont see why this doesnt work.

The "I" part of the phrase is missing from the doc.

Generally it's advisable to combine multiple matching strategies as should clauses in one bool request.
You can have (in order of strictness..)

  1. Phrase matches
  2. OR matches
  3. fuzzy matches

Documents that match all of the criteria will rank highest while those that match only one clause will rank lower. Boosts on particular clauses may help.
Avoid making the sloppier queries too sloppy or you'll create a "long tail" of low-quality results which will mess up any aggregation counts or make sorting by anything other than relevance reveal lots of low-quality matches.

I see your point.

However, is there any way to use minimum_should_match with the match_phrase query because I need to take account of the words order ?

No - there's a "slop" setting for how far apart the words can be but currently nothing that permits dropping of a number of terms from the phrase.

I already tried the "slop" setting but it seems not working though.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.