ES基础查询语法

普通查询,多条件查询
must term 类似数据库 =
must terms 类似于数据库查询的 in
must_not term 类型数据库的 !=
must_not terms 类型于数据库查询的 not in

POST /exp-order-v1-benchmark-202010/_search
{
	"query": {
		"bool": {
			"must": [{
				"terms": {
					"orderStatus": [
						4, 5
					]
				}
			},{
			  "term": {
			    "billId": {
			      "value": "1146949448946155522"
			    }
			  }
			}],
			"filter": {
			  "term": {
			    "orderType": "1"
			  }
			}
		}
	}
}
POST /exp-order-v1-benchmark-202010/_search
{
	"query": {
		"bool": {
			"must": [{
				"terms": {
					"orderStatus": [
						4, 5
					]
				}
			},{
			  "term": {
			    "billId": {
			      "value": "1146949448946155522"
			    }
			  }
			}],
			"filter": {
			  "term": {
			    "orderType": "9"
			  }
			}
		,
		  "must_not": [
		    {
		      "term": {
		        "orderStatus": {
		          "value": "4"
		        }
		      }
		    }
		  ]
		}
	}
}

count查询条数
range里是范围查询

POST /exp-order-v1-benchmark-202010/_count
{
  "query": {
    "range": {
      "billCreateTime": {
        "gte": 1603814409000,
        "lte": 1603900809000
      }
    }
  }
}

group by ,根据billSenderCityId字段进行分组,可以查询获取到每个桶的个数

POST /exp-order-v1-benchmark-202010/_search
{
	"query": {
		"range": {
			"billCreateTime": {
				"gte": 1603814409000,
				"lte": 1603900809000
			}
		}
	},
	"size": 0,
	"aggregations": {
		"field1": {
			"terms": {
				"field": "billSenderCityId",
				"size": 20
			}
		}
	}
}

类似于count(distinct(billSenderCityId)),可以获取到去重后的billSenderCityId的个数
POST /exp-order-v1-benchmark-202010/_search

{
  "query": {
    "range": {
      "billCreateTime": {
        "gte": 1603814409000,
        "lte": 1603900809000
      }
    }
  },
  "aggs": {
    "field": {
      "cardinality": {
        "field": "billSenderCityId"
      }
    }
  },
  "size": 0
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值