查询所有
GET /products/_search
{
"query": {
"match_all": {}
}
}
根据关键词查询
GET /products/_search
{
"query": {
"term": {
"desc": {
"value": "好吃"
}
}
}
}
范围查询
GET /products/_search
{
"query": {
"range": {
"price": {
"gte": 10,
"lte": 30
}
}
}
}
前缀查询
GET /products/_search
{
"query": {
"prefix": {
"title": {
"value": "德芙"
}
}
}
}
通配符查询 (? 匹配一个字符 * 匹配多个字符)
GET /products/_search
{
"query": {
"wildcard": {
"title": {
"value": "*巧*"
}
}
}
}
多id查询
GET /products/_search
{
"query": {
"ids": {
"values": ["1", "2"]
}
}
}
模糊查询
GET /products/_search
{
"query": {
"fuzzy": {
"title": "甜很辣"
}
}
}
布尔查询
GET /products/_search
{
"query": {
"bool": {
"must_not": [
{
"ids": {
"values": [1]
}
},
{
"term": {
"title": {
"value": "法式小面包"
}
}
}
]
}
}
}
多字段查询
GET /products/_search
{
"query": {
"multi_match": {
"query": "浣猫",
"fields": ["title", "desc"]
}
}
}
默认字段分词查询 高亮
GET /products/_search
{
"query": {
"query_string": {
"default_field": "desc",
"query": "熊熊真可爱"
}
},
"highlight": {
"pre_tags": ["<span style='color:red;'>"],
"post_tags": ["</span>"],
"require_field_match": "false",
"fields": {
"*": {}
}
}
}
返回指定条数
GET /products/_search
{
"query": {
"match_all": {}
},
"size": 2
}
分页查询
GET /products/_search
{
"query": {
"match_all": {}
},
"size": 2,
"from": 2
}
指定字段排序
GET /products/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"id": {
"order": "asc"
}
}
]
}
返回指定字段
GET /products/_search
{
"query": {
"match_all": {}
},
"_source": ["title", "desc"]
}
分词器
POST /_analyze
{
"analyzer": "whitespace",
"text": "this is a , good Man 中华人民共和国"
}
ik分词器
POST /_analyze
{
"analyzer": "ik_max_word",
"text": "中华人民共和国国歌"
}
过滤查询
GET /products/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": [
{
"terms": {
"desc": [
"甜不辣",
"真的"
]
}
}
]
}
}
}
评论区