ES 入门记录之 match和term查询的区别

时间:2024-01-08 08:40:50

ElasticSearch 系列文章

1 ES 入门之一 安装ElasticSearcha

2 ES 记录之如何创建一个索引映射

3 ElasticSearch 学习记录之Text keyword 两种基本类型区别

4 ES 入门记录之 match和term查询的区别

5 ElasticSearch 学习记录之ES几种常见的聚合操作

6 ElasticSearch 学习记录之父子结构的查询

7 ElasticSearch 学习记录之ES查询添加排序字段和使用missing或existing字段查询

8 ElasticSearch 学习记录之ES高亮搜索

9 ElasticSearch 学习记录之ES短语匹配基本用法

10 ElasticSearch 学习记录之 分布式文档存储往ES中存数据和取数据的原理

11 ElasticSearch 学习记录之集群分片内部原理

12 ElasticSearch 学习记录之ES如何操作Lucene段

13 ElasticSearch 学习记录之如任何设计可扩容的索引结构

14 ElasticSearch之 控制相关度原理讲解

match和term查询的区别

match

- match的查询词会被分词

- match_phrase 不会分词

- match_phrase 可对多个字段进行匹配

term

- term代表完全匹配,不进行分词器分析

- term 查询的字段需要在mapping的时候定义好,否则可能词被分词。传入指定的字符串,查不到数据

bool联合查询

- must should must_not

- must 完全匹配

- should 至少满足一个

- must_not不匹配

举个栗子

		{
"query": {
"bool": {
"must": {
"term": {
"content": "宝马"
}
},
"must_not": {
"term": {
"tags": "宝马"
}
}
}
}
}
一个简单的查询
POST product/_search
{
"size": 20,
"query": {
"bool": {
"must": [
{
"term": {
"attribute": {
"value": "13"
}
}
},
{
"match": {
"departureCitys": "上海"
}
}
]
}
}
}