【ES从入门到实战】十六、全文检索-ElasticSearch-进阶-term查询

本文详细解析了Elasticsearch中match与term查询的区别,强调了全文检索与精确匹配的应用场景,通过实例展示了如何针对不同字段类型选择合适的检索方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接第15节

8)、term

和 match 一样。匹配某个属性的值。全文检索字段用 match,其他非 text 字段匹配用 term

Avoid using the term query for text fields.

By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field values difficult.

To search text field values, use the match query instead.

非文本值使用 term 检索:

GET /bank/_search
{
  "query": {
    "term": {
      "age":28
    }
  }
}

在这里插入图片描述

match 的 xxx.keyword,文本的精确匹配检索:

GET /bank/_search
{
  "query": {
    "match": {
      "address.keyword": "789 Madison"
    }
  }
}

在这里插入图片描述

match 全文分词匹配:

GET /bank/_search
{
  "query": {
    "match": {
      "address": "789 Madison"
    }
  }
}

在这里插入图片描述

match_phrase,将需要匹配的值当成一个整体单词(不分词)进行检索:

GET /bank/_search
{
  "query": {
    "match_phrase": {
      "address": "789 Madison"
    }
  }
}

在这里插入图片描述

注意:如果对于文本值使用 term 检索时,并不会进行分词,而是精确检索,所以可能会匹配不到数据:

GET /bank/_search
{
  "query": {
    "term": {
      "address": "789 Madison"
    }
  }
}

在这里插入图片描述

参考文档-query-dsl-term-query

参考文档-query-dsl


参考:

Elasticsearch Reference

elastic

全文搜索引擎 Elasticsearch 入门教程

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值