java操作es聚合操作并显示其他字段_java操作elasticsearch实现组合桶聚合
java操作es聚合操作并显⽰其他字段_java操作elasticsearch实
现组合桶聚合
1、terms分组查询社保能取出来吗
//分组聚合
@Test
public void test40() throws UnknownHostException{
//1、指定es集 cluster.name 是固定的key值,my-application是ES集的名称
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
//2.创建访问ES服务器的客户端
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new ByName("192.168.1.94"), 9300));
/
/以年龄分组,组名为:terms
AggregationBuilder builder = s("terms").field("age");
SearchResponse response = client.prepareSearch("lib3").addAggregation(builder).execute().actionGet();
Terms terms = Aggregations().get("terms");
手机回qq密码for(Terms.Bucket Buckets()) {
System.out.Key()+" "+DocCount());
}
}
2、terms query聚合查询
//filter聚合
@Test
public void test41() throws UnknownHostException{
//1、指定es集 cluster.name 是固定的key值,my-application是ES集的名称
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
//2.创建访问ES服务器的客户端
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new ByName("192.168.1.94"), 9300));
//以年龄分组,并查询年龄为20的有多少⼈
QueryBuilder queryBuilder = Query("age", 20);
AggregationBuilder builder = AggregationBuilders.filter("filter",queryBuilder);
SearchResponse response = client.prepareSearch("lib3").addAggregation(builder).execute().actionGet();
Filter filter = Aggregations().get("filter");
System.out.DocCount());
}
3、filters聚合
//filters聚合:指定多个过滤条件
@Test
public void test42() throws UnknownHostException{
//1、指定es集 cluster.name 是固定的key值,my-application是ES集的名称
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
//2.创建访问ES服务器的客户端
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new ByName("192.168.1.94"), 9300));
/
/查询heijiu changge中各有多少个⽂档
QueryBuilder queryBuilder = Query("interests", "hejiu");
QueryBuilder queryBuilder2 = Query("interests", "changge");
AggregationBuilder builder = AggregationBuilders.filters("filters",queryBuilder,queryBuilder2); SearchResponse response = client.prepareSearch("lib3").addAggregation(builder).execute().actionGet(); Aggregation filter = Aggregations().get("filters");
System.out.String());
}
4、range聚合
//range聚合:范围分组过滤条件
@Test
public void test43() throws UnknownHostException{
//1、指定es集 cluster.name 是固定的key值,my-application是ES集的名称
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
//2.创建访问ES服务器的客户端
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new ByName("192.168.1.94"), 9300));
//统计年龄在50以下的,年龄在25⾄50之间,年龄在25以上的⼈数
AggregationBuilder builder = AggregationBuilders
.range("range")
.field("age")
.addUnboundedTo(50)
.
addRange(25,50)
.addUnboundedFrom(25);
SearchResponse response = client.prepareSearch("lib3").addAggregation(builder).execute().actionGet();
低频噪音如何处理Aggregation filter = Aggregations().get("range");
System.out.String());
}
5、missing聚合
//missing聚合:为空聚合统计
@Test
public void test44() throws UnknownHostException{
//1、指定es集 cluster.name 是固定的key值,my-application是ES集的名称
Settings settings = Settings.builder().put("cluster.name", "my-application").build();
//2.创建访问ES服务器的客户端
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new ByName("192.168.1.94"), 9300));
//统计价格为空的个数
AggregationBuilder builder = AggregationBuilders.missing("missing").field("price");
SearchResponse response = client.prepareSearch("lib4").addAggregation(builder).execute().actionGet();
Aggregation filter = Aggregations().get("missing");
System.out.String());
}
技术在于交流!
java操作elasticsearch实现query String
1.CommonTersQuery: 指定字段进⾏模糊查询 //commonTermsQuery @Test public void test35() throws UnknownHostExcept ...
java操作elasticsearch实现聚合查询
1.max 最⼤值 //max 求最⼤值 @Test public void test30() throws UnknownHostException{ //1.指定es集 cluster.name ...
java操作elasticsearch实现前缀查询、wildcard、fuzzy模糊查询、ids查询
1.前缀查询(prefix) //prefix前缀查询 @Test public void test15() throws UnknownHostException { //1.指定es集 clus ...
java操作elasticsearch实现条件查询(match、multiMatch、term、terms、reange)
1.条件match query查询 //条件查询match query @Test public void test10() throws UnknownHostException { //1.指定e ...
java操作elasticsearch实现查询删除和查询所有
后期博客本⼈都只给出代码,具体的说明在代码中也有注释. 1.查询删除 //查询删除:将查询到的数据进⾏删除 @Test public void test8() throws UnknownHostEx ...
java操作elasticsearch实现批量添加数据(bulk)
java操作elasticsearch实现批量添加主要使⽤了bulk 代码如下: //bulk批量操作(批量添加) @Test public void test7() throws IOExcepti ...
如何练好普通话java操作elasticsearch实现基本的增删改查操作
⼀.在进⾏java操作elasticsearch之前,请确认好集的名称及对应的ES节点ip和端⼝ 1.查看ES的集名称 #进⼊l配置⽂件/opt/elasticse ...
Java操作ElasticSearch之创建客户端连接
Java操作ElasticSearch之创建客户端连接 3 发布时间:『 2017-09-11 17:02』  博客类别:elasticsearch  阅读(3157) Java操作ElasticSe ...
java 操作elasticsearch之搭建测试项⽬环境
在创建项⽬之前请确认maven是否安装好,在此我是以环境都搭建好的情况下进⾏⽰范,现在以eclipse开发⼯具为例,具体操作如下: 1.创建maven项⽬ File - new -other 2.在p ...
随机推荐
独一无二的近义词java CyclicBarrier
import java.io.IOException; import java.util.Random; import urrent.BrokenBarrierExcept ...
IO中同步、异步与阻塞、⾮阻塞的区别(转)
JS(⼀)
循环还是很有意思的: 1) 安全数的作业:
ubuntu 10.4⾮法关机后上不了⽹
⽤的好好的ubuntu 10.4,⾮法关机后居然上不了⽹,右上⾓的⽹络图标也不见了,还以为是⽹卡问题,进⼊xp,发现⼀切正常,⼼⾥不断地诅咒ubuntu,该死的ubuntu,我windows还天天⾮法 ...
详解HTTPS加速原理
HTTPS是什么? http叫超⽂本传输协议,使⽤TCP端⼝80,默认情况下数据是明⽂传送的,数据可以通过抓包⼯具捕获到,因此在interner上,有些⽐较重要的站点的http服务器需要使⽤PKI(公 ...
JavaWeb 例⼦ JDBC+JSP登陆注册留⾔板
注册页⾯:
Ural 1966 Cycling Roads
================ Cycling Roads ================  Description When Vova was in Shenzhen, he rented a ...
Elastic Story(⼀)暴风魔镜
关于_all 当索引⼀个⽂档的时候,Elasticsearch 取出所有字段的值拼接成⼀个⼤的字符串,作为 _all 字段进⾏索引.例如,当索引这个⽂档时: { "tweet": ...
python的学习之路day4
⼤纲 1.⼀些常⽤的内置函数 callable() chr() & ord() 随机⽣成验证码 map() 全局变量,局部变量 hash() & round() max() min() ...

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。