1.单个匹配查询 match query
{
"query": {
"match": {
"merchant_name":"健康"
}
}
}
2.查询所有 match_all
{"query":{"match_all":{"title":"标题一样"}}}
3.精确查询
{
"query":{
"term":{
"assistant_id": 200186
}
}
}
4.排序
{
"query":{
"term":{
"assistant_id": 200186
}
},
"sort":{
"_score":"asc"
}
}
5. 分页
{
"query":{
"term":{
"assistant_id": 200186
}
},
"from": 1, // 从几条数据开始
"size": 5 // 页数
}
6. 范围查询
{
"query":{
"range" : {
"x_created_at": {
"gte": "2021-09-07", // 大于等于
"lte": "2021-09-08" // 小于等于
}
}
}
}
7. 精确多个值查询 相当于in
{
"query":{
"terms":{
"assistant_id": [200186,200621]
}
}
}
8. bool 组合查询
must 相当于 and
must_not 相当于 !=
should 相当于or
// must 用法示例
{
"query": {
"bool": {
"must": [
// assistant_id = 200186 and merchat_name like "%你好%"
{"term": {"assistant_id":200186}},
{"match":{"merchant_name": "你好"}}
]
}
}
}
// should 用法示例
{
"query": {
"bool": {
"should": [
// assistant = 200186 or merchant_name like "%hello%"
{"term": {"assistant_id":200186}},
{"match":{"merchant_name": "hello"}}
]
}
}
}
// must_not 示例
{
"query": {
"bool": {
// channel != 1
"must_not": [
{"term": {"channel":1}}
]
}
}
}
// 组合范围排序
{
"query": {
"bool": {
"must": [
{"term": {"channel":1}},
{ "range":{
"x_created_at":{
"gte":"2021-09-06"
}
}}
]
}
},
"sort": {
"_score":"asc"
}
}