#记录聚合查询方法
from elasticsearch import Elasticsearch

es = Elasticsearch(['xx.xx.xx.xx:9200'])

#获取最小的年龄
res = es.search(index='test6', body = {
"query": {
"match_all": {}
},
"aggs": {
"min_age": {
"min": {
"field": "age"
}
}
}
})
print(res['aggregations']['min_age']['value']) #获取最大的年龄
res = es.search(index='test6', body = {
"query": {
"match_all": {}
},
"aggs": {
"max_age": {
"max": {
"field": "age"
}
}
}
})
print(res['aggregations']['max_age']['value']) #获取年龄和
res = es.search(index='test6', body = {
"query": {
"match_all": {}
},
"aggs": {
"sum_age": {
"sum": {
"field": "age"
}
}
}
})
print(res['aggregations']['sum_age']['value']) #获取平均年龄
res = es.search(index='test6', body = {
"query": {
"match_all": {}
},
"aggs": {
"avg_age": {
"avg": {
"field": "age"
}
}
}
})
print(res['aggregations']['avg_age']['value']) # from、size
#from:从“第几条”开始查询, size:查询多少条
res = es.search(index='test6', body = {
"query": {
"match_all": {}
},
"size": 1,
"from": 2
})
print(res)

python 使用 elasticsearch 常用方法(聚合)的更多相关文章

  1. python 查询 elasticsearch 常用方法(Query DSL)

    1. 建立连接 from elasticsearch import Elasticsearch es = Elasticsearch(["localhost:9200"]) 2. ...

  2. python 使用 elasticsearch 常用方法(检索)

    #记录es查询等方法 #清楚数据 curl -XDELETE http://xx.xx.xx.xx:9200/test6 #初始化数据 curl -H "Content-Type: appl ...

  3. python 使用 elasticsearch 常用方法(索引)

    #记录管理索引等方法 from elasticsearch import Elasticsearch es = Elasticsearch(['xx.xx.xx.xx:9200']) #获取文档内容r ...

  4. Python 和 Elasticsearch 构建简易搜索

    Python 和 Elasticsearch 构建简易搜索 作者:白宁超 2019年5月24日17:22:41 导读:件开发最大的麻烦事之一就是环境配置,操作系统设置,各种库和组件的安装.只有它们都正 ...

  5. Python操作ElasticSearch

    Python批量向ElasticSearch插入数据 Python 2的多进程不能序列化类方法, 所以改为函数的形式. 直接上代码: #!/usr/bin/python # -*- coding:ut ...

  6. 笔记13:Python 和 Elasticsearch 构建简易搜索

    Python 和 Elasticsearch 构建简易搜索 1 ES基本介绍 概念介绍 Elasticsearch是一个基于Lucene库的搜索引擎.它提供了一个分布式.支持多租户的全文搜索引擎,它可 ...

  7. python实现elasticsearch操作-CRUD API

    python操作elasticsearch常用API 目录 目录 python操作elasticsearch常用API1.基础2.常见增删改操作创建更新删除3.查询操作查询拓展类实现es的CRUD操作 ...

  8. python中os常用方法

    python中OS常用方法 Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问 ...

  9. Python 操作 ElasticSearch

    Python 操作 ElasticSearch 学习了:https://www.cnblogs.com/shaosks/p/7592229.html 官网:https://elasticsearch- ...

随机推荐

  1. Flask-Script Manager

    Flask Script扩展提供向Flask插入外部脚本的功能,包括运行一个开发用的服务器,一个定制的Python shell,设置数据库的脚本,cronjobs,及其他运行在web应用之外的命令行任 ...

  2. Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey

    Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey Invalid bound ...

  3. Activity间通过Intent交互及系统服务调用

    I. 实验目的通过本实验理解Android开发框架中最核心程序部件Activity间通过Intent交互的原理,掌握通过Intent传递参数和系统服务调用的方法,并通过实验中的3个具体的实验内容加深理 ...

  4. bytes与网络通信

    字符串是人机交互的符号: bytes是最接近计算机本身的信息表示方法. 网络通信是计算机与计算机之间的通信. 所有的通信信息,必须转化为bytes流的方式在计算机间传递. bytes与数据类型无关,与 ...

  5. GuGuFishtion HDU - 6390 (欧拉函数,容斥)

    GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...

  6. Spring Could Feign 设计原理

    什么是Feign? Feign 的英文表意为"假装,伪装,变形", 是一个http请求调用的轻量级框架,可以以Java接口注解的方式调用Http请求,而不用像Java中通过封装HT ...

  7. 第08组 Alpha冲刺(4/6)

    队名:955 组长博客:https://www.cnblogs.com/cclong/p/11882079.html 作业博客:https://edu.cnblogs.com/campus/fzu/S ...

  8. Dice Similarity Coefficent vs. IoU Dice系数和IoU

    Dice Similarity Coefficent vs. IoU Several readers emailed regarding the segmentation performance of ...

  9. 【BigData】Java基础_冒泡排序

    1.实现需求 根据已经存在的数组,使用冒泡排序将数组中的元素排序后输出. 2.代码 package cn.test.logan.day02; /** * 冒泡排序在数组上的实现 * @author Q ...

  10. Video Architecture Search

    Video Architecture Search 2019-10-20 06:48:26 This blog is from: https://ai.googleblog.com/2019/10/v ...