Elasticsearch全文搜索控制精准度

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26230421/article/details/82108028

前言

本文主要是关于全文搜索控制精准度的操作

其他搜索请参考:

使用kibana或postman操作Elasticsearch的常用命令

使用kibana或postman操作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!

猜你喜欢

转载自blog.csdn.net/qq_26230421/article/details/82108028