1. 程式人生 > >Elasticsearch全文搜尋控制精準度

Elasticsearch全文搜尋控制精準度

前言

本文主要是關於全文搜尋控制精準度的操作

其他搜尋請參考:

一、使用operator

搜尋結果中必須至少包括run、jump兩種愛好

GET people/_search
{
  "query": {
    "match": {
      "hobby": {
        "query": "run jump", 
        "operator": "and"
      }
    }
  }
}

二、使用百分比

搜尋結果中至少包括6個愛好中的一半,也就是3個

GET people/_search
{
  "query": {
    "match": {
      "hobby": {
        "query": "run jump basketball football piano pingpang", 
        "minimum_should_match": "50%"
      }
    }
  }
}

三、使用具體數量

使用數量,搜尋結果中必須至少包括3個愛好

GET people/_search
{
  "query": {
    "bool": {
      "should": [
        {"match": {
          "hobby": "basketball"
        }},
        {"match": {
          "hobby": "pingpang"
        }},
        {"match": {
          "hobby": "piano"
        }},
        {"match": {
          "hobby": "run"
        }}
      ],
      "minimum_should_match": 3
    }
  }
}

OK, GAME OVER!