Wednesday 11 November 2015

Elasticsearch: minimum_should_match : Specifying minimum match words


By using  minimum_should_match parameter, you can specify the number of terms that must match for a document to be considered relevant.
GET books/philosophy/_search
{
  "query":{
    "match":{
        "description":{
          "query" : "young transformation Egyptian",
          "minimum_should_match" : 2
        } 
    }
  }
}

Above query returns following response.
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.012596527,
      "hits": [
         {
            "_index": "books",
            "_type": "philosophy",
            "_id": "5",
            "_score": 0.012596527,
            "_source": {
               "pages": 240,
               "title": "Veronika Decides to Die: A Novel of Redemption",
               "description": "tells the story of a young woman's transformation from despairing would-be suicide to affirmed and then affirming survivor. This book offers an archetypal story of hope, portraying a situation in which joy, freedom, integrity and truth all remain possible under the most challenging and limiting of circumstances. In doing so, the narrative thematically explores the nature of insanity, the importance of living a genuine life, and the threats to individual identity imposed by closed communities and the rules under which they function.",
               "ISBN": "5955000836",
               "publisher": "Harper Perennial",
               "author": {
                  "firstName": "Mitch",
                  "lastName": "Albom"
               },
               "price": 420,
               "tags": [
                  "literature",
                  "fiction"
               ]
            }
         }
      ]
   }
}


You can specify “minimum_should_match” in percentage format also.

GET books/philosophy/_search
{
  "query":{
    "match":{
        "description":{
          "query" : "young transformation Egyptian",
          "minimum_should_match" : "70%"
        } 
    }
  }
}




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment