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.商品中 ...
随机推荐
- MyEclipse部署WebLogic
====================================================================================
- ReactNative: 搭建ReactNative开发环境
搭建ReactNative开发环境 不废话,具体步骤如下: 一.安装需要的软件 1.Homebrew Homebrew, Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件. /usr ...
- jquery所有版本下载外链地址
jquery-2.1.1 (注!jquery-2.0以上版本不再支持IE 6/7/8) 百度引用地址 (推荐目前最稳定的,不会出现延时打不开情况) 百度压缩版引用地址: <script src= ...
- AWK常用技巧
1.1 介绍 awk其名称得自于它的创始人 Alfred Aho .Peter Weinberger 和 Brian Kernighan 姓氏的首个字母.实际上 AWK 的确拥有自己的语言: AWK ...
- wifipineapple获取用户上网信息
ssh连接到wifipineapple: 输入连接信息:ssh root@172.16.42.1 输入密码:pineapplesareyummy 安装依赖基本环境: opkg update opkg ...
- KVM虚拟化管理 virt manager常用操作
部分涉及到Linux.Nginx.tomcat.MySQL等的点滴操作记录,时间长了,就忘掉了,偶尔整理一下操作的history,就此简要备份一下: [原][BG]-一次虚拟化环境实践简要记录: ht ...
- linux 切分文件
linux经常需要处理文件,如果文件比较大,那么需要切分成为若干的小文件再处理. 命令:split 比如有一个文件: ll -h 1431531915758 -rw-r--r-- 1 ticketde ...
- 简单shell指令
第一部分 简单的常用指令 1.date命令 date 2.显示日历 cal 3.显示当前目录 pwd 4.切换当前工作目录 默认情况下,超级用户的主目录是/root,而普通用户的主目录是/home下 ...
- linux备份数据mysql
到mysql安装目录下的bin: ./mysqldump -u root -p ebuy_mgt > /home/2017backup.sql
- [k8s]通过openssl生成证书
证书认证原理: http://www.cnblogs.com/iiiiher/p/7873737.html [root@m1 ssl]# cat master_ssl.cnf [req] req_ex ...