Hadoop -- ES -- CURD
1.获取ES连接
package com.ciic.history.common; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress; import java.net.InetAddress;
import java.net.UnknownHostException; public class DaoUtilL { private static TransportClient clientL = null; private DaoUtilL(){}; public static TransportClient getClientL() {
try {
if (null != clientL) {
return clientL;
}
Settings settings = Settings.settingsBuilder().put("cluster.name", "search1")
.put("transport.tcp.compress", true).build();
InetSocketTransportAddress address1 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.249"), 9300);
InetSocketTransportAddress address2 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.250"), 9300);
InetSocketTransportAddress address3 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.251"), 9300);
InetSocketTransportAddress address4 = new InetSocketTransportAddress(InetAddress.getByName("192.168.43.252"), 9300);
TransportAddress[] addressArr = {address1, address2, address3, address4};
clientL = TransportClient.builder().settings(settings).build().addTransportAddresses(addressArr);
return clientL;
} catch (Exception e) {
return null;
}
}
}
2.CURD操作
@Override
public JsonEntity queryCustomerPreview(int page, int rows) {
TransportClient clientL = DaoUtilL.getClientL();
SearchRequestBuilder builder = clientL.prepareSearch();
builder.setIndices("esinner_limecustomerpreview_index").
setTypes("xian").
addSort("imscustomername", SortOrder.ASC).setFrom((page-1)*rows).setSize(rows); SearchResponse response = builder.get();
SearchHit[] searchHits = response.getHits().getHits();
ArrayList arrayList = new ArrayList();
for(int i = 0; i < searchHits.length; i++) {
arrayList.add(searchHits[i].getSource());
}
//查询总记录数total
SearchResponse totalResponse = clientL.prepareSearch()
.setIndices("esinner_limecustomerpreview_index")
.setSearchType(SearchType.COUNT).setSize(0).get();
long length = response.getHits().totalHits(); JsonEntity entity = new JsonEntity();
entity.setTotal(length);
entity.setRows(arrayList);
return entity;
}
-- -- -- -- -- --
@Override
public JsonEntity customerPreviewSearch(EsinnerLimeCustomerPreviewIndex customerPreview, int page, int rows) {
TransportClient clientL = DaoUtilL.getClientL();
SearchRequestBuilder searchRequestBuilder = clientL.prepareSearch();
searchRequestBuilder.setIndices("esinner_limecustomerpreview_index").
setTypes("xian").setSearchType(SearchType.DEFAULT).
setFrom((page-1)*rows).setSize(rows); BoolQueryBuilder builder = QueryBuilders.boolQuery(); boolean flag=true;
if(StringUtils.isNotBlank(customerPreview.getImscustomername())){
flag=false;
builder.must(QueryBuilders.termQuery("imscustomername",customerPreview.getImscustomername()));
}
if(StringUtils.isNotBlank(customerPreview.getImscustomercode())){
flag=false;
builder.must(QueryBuilders.matchQuery("imscustomercode",customerPreview.getImscustomercode()));
}
if(flag==true){
searchRequestBuilder.addSort("imscustomercode", SortOrder.ASC);
}
searchRequestBuilder.setQuery(builder); SearchResponse response = searchRequestBuilder.get();
SearchHit[] searchHits = response.getHits().getHits();
ArrayList arrayList = new ArrayList();
for(int i = 0; i < searchHits.length; i++) {
arrayList.add(searchHits[i].getSource());
} SearchResponse totalResponse = clientL.prepareSearch()
.setIndices("esinner_limecustomerpreview_index")
.setSearchType(SearchType.COUNT).setSize(0).get();
long length = response.getHits().totalHits();
JsonEntity entity = new JsonEntity(); entity.setTotal(length);
entity.setRows(arrayList); return entity;
}
-- -- -- -- -- --
3.返回数据
啦啦啦
Hadoop -- ES -- CURD的更多相关文章
- Elastic Stack 笔记(十)Elasticsearch5.6 For Hadoop
博客地址:http://www.moonxy.com 一.前言 ES-Hadoop 是连接快速查询和大数据分析的桥梁,它能够无间隙的在 Hadoop 和 ElasticSearch 上移动数据.ES ...
- mesos概述
mesos解决的问题 不同的分布式运算框架(spark,hadoop,ES,MPI,Cassandra,etc.)中的不同任务往往需要的资源(内存,CPU,网络IO等)不同,它们运行在同一个集群中,会 ...
- zabbix基本介绍
来源是 觅安教育 大家有兴趣可以去哔哩哔哩搜搜. Open-falcon是由小米公司开源 比如windows,linux,unix,openBSD,AIX,solaris,Mac等操作系统,都可以安装 ...
- 使用Observer实现HBase到Elasticsearch的数据同步
最近在公司做统一日志收集处理平台,技术选型肯定要选择elasticsearch,因为可以快速检索系统日志,日志问题排查及功业务链调用可以被快速检索,公司各个应用的日志有些字段比如说content是不需 ...
- FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) :
在hive命令行创建表时报错: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. ...
- es第十篇:Elasticsearch for Apache Hadoop
es for apache hadoop(elasticsearch-hadoop.jar)允许hadoop作业(mapreduce.hive.pig.cascading.spark)与es交互. A ...
- 基本环境安装: Centos7+Java+Hadoop+Spark+HBase+ES+Azkaban
1. 安装VM14的方法在 人工智能标签中的<跨平台踩的大坑有提到> 2. CentOS分区设置: /boot:1024M,标准分区格式创建. swap:4096M,标准分区格式创建. ...
- Hive创建表格报【Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException】引发的血案
在成功启动Hive之后感慨这次终于没有出现Bug了,满怀信心地打了长长的创建表格的命令,结果现实再一次给了我一棒,报了以下的错误Error, return code 1 from org.apache ...
- #研发解决方案介绍#基于ES的搜索+筛选+排序解决方案
郑昀 基于胡耀华和王超的设计文档 最后更新于2014/12/3 关键词:ElasticSearch.Lucene.solr.搜索.facet.高可用.可伸缩.mongodb.SearchHub.商品中 ...
随机推荐
- js常用事件
为了便于使读者更好地运用js事件,就把常用事件大致分为以下几种: a. 表单元素事件,在表单元素中生效 onfocus ------获取焦点 onblur -------失去焦点 onsubmit ...
- linux常用服务程序一键安装
PHP7安装 rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm service php-fpm stop yum remove php5* ...
- 在Springboot2.0项目中使用Druid配置多数据源
在Springboot出现之前配置数据源以及相关的事物,缓存等内容一直是个繁琐的工作,但是Springboot出现后这些基本都可以靠默认配置搞定,就变得很轻松了.这就是现在推崇模板>配置的原因, ...
- 移动基于Percona XTRADB Cluster的大数据解决方式
移动基于Percona XTRADB Cluster的大数据解决方式 一.移动的去IOE之旅 近期由于"棱镜门"事件的曝光.引起了国家对信息安全问题的注 ...
- python dash 初探 --- k 线国内版
python dash 的应用首页,是用一个 k 线图来做 damo 的,奈何数据源用的 Google,上不去.当然,可以换 yahoo,但是毕竟国内的还是更亲切些. 官方的 demo 用的 pand ...
- Java 迭代器综述
一.摘要 迭代器模式是与集合共生共死的.一般来说.我们仅仅要实现一个容器,就须要同一时候提供这个容器的迭代器.使用迭代器的优点是:封装容器的内部实现细节,对于不同的集合,能够提供统一的遍历方式,简化c ...
- WinDbg下载符号文件
设置添加系统环境变量_NT_SYMBOL_PATH 的值为:srv*c:\symbols*http://msdl.microsoft.com/download/symbols 这样启动WinDbg的时 ...
- Bash 中的特殊字符大全【转】
Linux下无论如何都是要用到shell命令的,在Shell的实际使用中,有编程经验的很容易上手,但稍微有难度的是shell里面的那些个符号,各种特殊的符号在我们编写Shell脚本的时候如果能够用的好 ...
- 0x01 Spring Cloud 概述
Spring Cloud Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁定,领导选举,分 ...
- Json返回结果为null属性不显示解决方法
返回时null属性不显示:String str = JSONObject.toJSONString(obj); 返回为null属性显示:String str = JSONObject.toJSONSt ...