match_phrase和match_phrase_prefix区别

match_phrase和match_phrase_prefix针对于短语匹配场景

match_phrase是用于精确匹配整个短语的查询,而match_phrase_prefix是在查询末尾添加前缀以匹配短语的一部分。例如,如果短语是“the quick brown fox jumping over the lazy dog”,那么一个match_phrase查询需要输入“brown fox”才能匹配,输入"brown fo则不能匹配",而一个match_phrase_prefix查询可以匹配“quick b”,“quick br”,“quick bro”等前缀。简单来说,match_phrase要求完全匹配,而match_phrase_prefix允许前缀匹配。

match_phrase查询:

GET /job/_search
{
  "query": {
    "match_phrase": {
      "content": "brown fox"
    }
  }
}
结果:
{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.7316709,
    "hits" : [
      {
        "_index" : "job",
        "_type" : "_doc",
        "_id" : "jaOtEYcBL5xiQSCxz8-d",
        "_score" : 2.7316709,
        "_source" : {
          "_class" : "com.bj58.chr.springdataes.use.domain.Job",
          "name" : "the quick brown fox jumping over the lazy dog",
          "content" : "the quick brown fox jumping over the lazy dog",
          "address" : "河南省郑州市金水区",
          "suggest" : {
            "input" : [
              "河南省郑州市金水区"
            ]
          },
          "createTime" : "20230324",
          "updateTime" : "20230324"
        }
      }
    ]
  }
}
GET /job/_search
{
  "query": {
    "match_phrase": {
      "content": "brown fo"
    }
  }
}

结果
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

match_phrase_prefix查询

GET /job/_search
{
  "query": {
    "match_phrase_prefix": {
      "content": "brown fox"
    }
  }
}

结果:
{
  "took" : 6,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.7316709,
    "hits" : [
      {
        "_index" : "job",
        "_type" : "_doc",
        "_id" : "jaOtEYcBL5xiQSCxz8-d",
        "_score" : 2.7316709,
        "_source" : {
          "_class" : "com.bj58.chr.springdataes.use.domain.Job",
          "name" : "the quick brown fox jumping over the lazy dog",
          "content" : "the quick brown fox jumping over the lazy dog",
          "address" : "河南省郑州市金水区",
          "suggest" : {
            "input" : [
              "河南省郑州市金水区"
            ]
          },
          "createTime" : "20230324",
          "updateTime" : "20230324"
        }
      }
    ]
  }
}
GET /job/_search
{
  "query": {
    "match_phrase_prefix": {
      "content": "brown fo"
    }
  }
}

结果:
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.7316709,
    "hits" : [
      {
        "_index" : "job",
        "_type" : "_doc",
        "_id" : "jaOtEYcBL5xiQSCxz8-d",
        "_score" : 2.7316709,
        "_source" : {
          "_class" : "com.bj58.chr.springdataes.use.domain.Job",
          "name" : "the quick brown fox jumping over the lazy dog",
          "content" : "the quick brown fox jumping over the lazy dog",
          "address" : "河南省郑州市金水区",
          "suggest" : {
            "input" : [
              "河南省郑州市金水区"
            ]
          },
          "createTime" : "20230324",
          "updateTime" : "20230324"
        }
      }
    ]
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值