term 根据 keyword字段 精确匹配
实例
GET index3/_search
{
"query": {
"term": {
"book_name": "设计"
}
}
}
2. terms
terms 根据 keyword字段 精确匹配
实例
GET index3/_search
{
"query": {
"terms": {
"book_name": ["设计", "李四"]
}
}
}
3. match
进行模糊查询
实例
GET index3/_search
{
"query": {
"match": {
"book_name": "设计"
}
}
}
4. multi_match
多个字段进行模糊查询
实例
GET index3/_search
{
"query": {
"multi_match": {
"query": "java"
"fileds": ["book_name", "author"]
}
}
}
5. values
根据多个id查询多个document
实例
GET index3/_search
{
"query": {
"ids": {
"values": ["1", "2", '3']
}
}
}
6. prefix
根据指定字段前缀进行查询
实例
GET index3/_search
{
"query": {
"prefix": {
"author": {
"value": "张"
}
}
}
}
7. fuzzy
模糊查询,输入大概的内容,es检索相关的数据
实例
GET index3/_search
{
"query": {
"fuzzy": {
"book_name": {
"value": "jav" #查询java
}
}
}
}
8. wildcard
正则查询
实例
GET index3/_search
{
"query": {
"wildcard": {
"author": {
"value": "张*"
}
}
}
}
9. range
根据范围查询
实例
GET index3/_search
{
"query": {
"range": {
"book_id": {
"gte": "101",
"lte": "105"
}
}
}
}
10. 分页查询
分页查询
实例
GET index3/_search
{
"query": {
“match_all”: {} # 匹配所有数据
},
_source: ["book_id", "book_name"], # 指定查询的数据
"from": 0,
"size": 20
}
}
11. bool -> must(and)、should(or)、 must_not(not)
复合查询
实例
GET index3/_search
{
"query": {
“bool”: {
"must": [
{
"match": {
"book_name": "java"
}
},
{
"match": {
"author": "张三"
}
},
]
}
}
}
11. filter
与must用法一样,不计算分数,会对经常被过滤的数据添加缓存
实例
GET index3/_search
{
"query": {
“bool”: {
"filter": [
{
"match": {
"book_name": "java"
}
},
{
"match": {
"author": "张三"
}
},
]
}
}
}
11. highlight
高亮查询
实例
GET index3/_search
{
"query": {
"multi_match": {
"query": "java",
"fileds": ["book_name", book_author]
}
},
_source: ["book_id", "book_name", "book_author"],
"highlight": {
"fields": {
"book_name": {}
},
"pre_tags": "


