当前位置: 首页 > news >正文

Elasticsearch一些函数查询

1. 根据价格分组统计数量,每组区间为2000,

filter_path=aggregations 设置查询结果只展示函数结果

也有date_histogram函数根据日期分组等等

GET order/_search?filter_path=aggregations
{"aggs": {"hist_price": {"histogram": {"field": "price","interval": 2000,# "min_doc_count": 1  # 设置只有数量大于1的才会展示}}}
}
查询结果:
{"aggregations" : {"hist_price" : {"buckets" : [{"key" : 0.0,"doc_count" : 1},{"key" : 2000.0,"doc_count" : 4},{"key" : 4000.0,"doc_count" : 0},{"key" : 6000.0,"doc_count" : 1}]}}
}

 2. 查询20%之内,50%之内,100%之内的价格都在多少钱之下

查询结果为近似值跟ES的算法有关

GET order/_search?filter_path=aggregations
{"aggs": {"percent_price": {"percentiles": {"field": "price","percents": [20,50,100]}}}
}
查询结果:
{"aggregations" : {"percent_price" : {"values" : {"20.0" : 1700.0000000000002,"50.0" : 2500.0,"100.0" : 6000.0}}}
}

3. 查询2的相反情况,例:查询2000,和 6000之内的占比

GET order/_search?filter_path=aggregations
{"aggs": {"percent_price": {"percentile_ranks": {"field": "price","values": [2000,6000]}}}
}
查询结果:
{"aggregations" : {"percent_price" : {"values" : {"2000.0" : 16.666666666666664,"6000.0" : 82.73866923818709}}}
}

http://www.lryc.cn/news/251235.html

相关文章:

  • 竞赛选题 : 题目:基于深度学习的水果识别 设计 开题 技术
  • Linux expect命令详解
  • ubuntu18编译Android8的Failed to contact Jack server问题
  • FindSecBugs支持的检测规则
  • 【WPF.NET开发】WPF.NET桌面应用开发概述
  • 态势感知是什么
  • Spring MVC常用的注解, Controller注解的作用,RequestMapping注解的作用 @ResponseBody注解的作用
  • 「Verilog学习笔记」自动贩售机1
  • 【大模型】更强的 ChatGLM3-6B 来了,开源可商用
  • Maxscript到Python转换工具教程
  • Spark_日期参数解析参数-spark.sql.legacy.timeParserPolicy
  • C语言之结构体
  • 【蓝桥杯软件赛 零基础备赛20周】第5周——高精度大数运算与队列
  • C#:程序发布的大小控制
  • Python中的split()、rsplit()、splitlines()的区别
  • 上位机开发框架:QT与winform/wpf对比
  • Halcon tiff 点云读取以及平面矫正
  • 详解Spring中基于注解的Aop编程以及Spring对于JDK和CGLIB代理方式的切换
  • 百度/抖音/小红书/微信搜索品牌形象优化怎么做?
  • 爬虫学习(三)用beautiful 解析html
  • OSG编程指南<十四>:OSG纹理渲染之普通纹理、多重纹理、Mipmap多级渐远纹理及TextureRectangle矩阵纹理
  • Langchain-Chatchat的安装过程
  • Windows系列:Windows Server 2012 R2 安装VMware Tools的正确姿势(实现物理机和虚拟机文件互传)
  • 最长连续递增序列
  • FreeRTOS入门--任务
  • 4个解决特定的任务的Pandas高效代码
  • 【已解决】AttributeError: module ‘gradio‘ has no attribute ‘Image‘
  • 高级软件工程15本书籍
  • 计网Lesson3 - 计算机网络评价指标与封包解包
  • 深度学习好文记录,反复学习