(27条消息) es 排序 聚合统计_吐血整理:一文看懂ES的R,查询与聚合_weixin_39901439的博客-CSDN博客
模糊匹配
select * from company where name like '%康康%'
GET red/_search
{
"query": {
"match": {
"companyname": "康康"
}
}
}
上述查询会查出姓名中带有“康康”字的文档
GET red/_search
{
"query": {
"match_phrase": { #match_phrase 查询的词,顺序不能变
"companyname": "江苏省水"
}
}
}
分页查询
select * from company limit 0,10
GET red/_search
{
"from": 0,
"size": 5
}
【注意】from+size不能大于10000,也可以进行修改,但不建议这么操作,因为es主要分片模式,其会在每个分片都会执行一样的查询,然后再进行汇总排序,如果数据太大,会撑爆内存。例如每个分片都查询出10000条,总共5个分片,最后就会进行50000条数据的排序,最后再取值。
范围查询并进行排序
select * from company where redtime>=10 and redtime<=50 order by redtime desc
GET red/_search
{
"query": {
"range": {
"redtime": {
"gte": "2012-08-23",
"lte": "2013-01-30"
}
}
},
"sort": [
{
"redtime": {
"order": "desc"
}
}
]
}
多字段匹配查询
select * from company where sex like '%男%' or name like '%男%'
GET red/_search
{
"query": {
"multi_match": {
"query": "鸡",
"fields": ["companyname","title"]
}
}
}
bool查询(结构化查询)
结构化查询主要有三块,分别是must,should,must_not,filter
(1)must:里面的条件都是“并”关系,都匹配
(2)should:里面的条件都是“或”关系,有一个条件匹配就行
(3)must_not:里面的条件都是“并”关系,都不能匹配
(4)filter:过滤查询,不像其它查询需要计算_score相关性,它不进行此项计算,故比query查询快
select * from company where provinceid=50
and departments like '市场部'
GET red/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"provinceid": "330000"
}
}
],
"filter": [
{
"match":{
"companyname":"大"
}
}
]
}
}
}
cbi360.net.apiwebjzw
cbi360.net.apijzw
聚合(指标聚合)
select max(age) from company
#取最大、最小、平均、总和
GET red/_search
{
"aggs": {
"provinceid_Max": {
"max": {
"field": "provinceid"
}
}
},
"size": 1
}
#对某个字段的值进行去重之后再取总数
select count(distinct(sex)) from company
GET red/_search
{
"aggs": {
"provinceid_Max": {
"cardinality": {
"field": "provinceid"
}
}
},
"size": 1
}
#stats聚合,对某个字段一次性返回count,max,min,avg和sum五个指标
select count(distinct age),sum(age),avg(age),max(age),min(age) from company
GET red/_search
{
"aggs": {
"provinceid_stats": {
"stats": {
"field": "provinceid"
}
}
},
"size": 1
}
percentiles聚合,对某个字段的值进行百分位统计 (统计各个值出现的百分比)
GET red/_search
{
"aggs": {
"provinceid_stats": {
"percentiles": {
"field": "provinceid"
}
}
},
"size": 1
}
聚合(桶聚合)
select sex,count(1) from company group by sex 分组
GET red/_search
{
"aggs": {
"provinceid_stats": {
"terms": {
"field": "provinceid"
}
}
},
"size": 1
}
private readonly JudgementService judgementService;
private readonly CourtAnnouncementService courtAnnouncementService;
private readonly CourtNoticeService courtNoticeService;
private readonly DishonestService dishonestService;
private readonly DishonestExecutorService dishonestExecutorService;
private readonly BusinessRiskService businessRiskService;
private readonly MPledgeService mPledgeService;
private readonly PenaltyService penaltyService;
private readonly PledgeService pledgeService;
Max:1271923
Min:502
1188
Es优化: (21条消息) ES 性能调优,这可能是全网最详细的 Elasticsearch 性能调优指南_Elastic开源社区的博客-CSDN博客_es调优
标签:search,聚合,GET,private,查询,es,排序,provinceid,red From: https://www.cnblogs.com/kkbk/p/17701837.html