package es53_Test;
import java.net.InetAddress;
import java.util.*;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class TestEsClient {
public static void main(String[] args) {
// add();//添加
// del();//删除
// upd();//修改
sel();//查询
}
//---------------------------------------------------------------------------------------------------------
public static void add(){
Client client = ESUtils.getEsClient();
IndexResponse indexResponse =
client.prepareIndex().setIndex(ESUtils.getIndexName())
.setType(ESUtils.getTypeName())
.setSource("{\"prodId\":1,\"prodName\":\"ipad5\",\"prodDesc\":\"比你想的更强大\",\"catId\":1}")
.setId("1")
.execute()
.actionGet();
System.out.println("添加成功,isCreated="+indexResponse.toString());
ESUtils.closeClient(client);
}
public static void del(){
Client client = ESUtils.getEsClient();
DeleteResponse delResponse =
client.prepareDelete().setIndex(ESUtils.getIndexName())
.setType(ESUtils.getTypeName())
.setId("1")
.execute()
.actionGet();
System.out.println("del is found="+delResponse.toString());
}
public static void upd(){
Client client = ESUtils.getEsClient();
GetResponse getResponse =
client.prepareGet().setIndex(ESUtils.getIndexName())
.setType(ESUtils.getTypeName())
.setId("1")
.execute()
.actionGet();
System.out.println("berfore update version="+getResponse.getVersion());
UpdateResponse updateResponse =
client.prepareUpdate().setIndex(ESUtils.getIndexName())
.setType(ESUtils.getTypeName())
.setDoc("{\"prodId\":1,\"prodName\":\"ipad5\",\"prodDesc\":\"比你想的更强大噢耶\",\"catId\":1}")
.setId("1")
.execute()
.actionGet();
System.out.println("更新成功,isCreated="+updateResponse.toString());
getResponse =
client.prepareGet().setIndex(ESUtils.getIndexName())
.setType(ESUtils.getTypeName())
.setId("1")
.execute()
.actionGet();
System.out.println("get version="+getResponse.getVersion());
System.out.println("-----upd----ok-----");
}
public static void sel(){
Client client = ESUtils.getEsClient();
//初始化查询条件
QueryBuilder query = QueryBuilders.matchQuery("prodName", "ipad5");
SearchResponse SearchResponseresponse = client.prepareSearch(ESUtils.INDEX_NAME)
//设置查询条件,
.setQuery(query)
.setFrom(0).setSize(60)
.execute()
.actionGet();
/**
* SearchHits是SearchHit的复数形式,表示这个是一个列表
*/
SearchHits shs = SearchResponseresponse.getHits();
System.out.println("总共有:"+shs.hits().length);
for(SearchHit hit : shs){
System.out.println(hit.getSourceAsString());
}
client.close();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
关于elasticsearch5.3.0基础增删改查实例文件
共67个文件
jar:52个
prefs:3个
properties:3个
5星 · 超过95%的资源 需积分: 10 58 下载量 51 浏览量
2017-07-10
12:18:17
上传
评论 1
收藏 23.88MB RAR 举报
温馨提示
关于elasticsearch5.3.0基础增删改查 开源共享 方便他人 赠人玫瑰 手有余香
资源推荐
资源详情
资源评论
收起资源包目录
es_5_3.rar (67个子文件)
es_5_3
.project 558B
src
log4j2.properties 203B
es53_Test
TestEsClient.java 4KB
ESUtils.java 2KB
target
classes
log4j2.properties 203B
META-INF
MANIFEST.MF 103B
maven
es_5_3
es_5_3
pom.properties 198B
pom.xml 1KB
es53_Test
TestEsClient.class 6KB
ESUtils.class 2KB
dependency
hppc-0.7.1.jar 1.09MB
lucene-spatial-extras-6.4.1.jar 192KB
lucene-spatial3d-6.4.1.jar 231KB
lucene-analyzers-common-6.4.1.jar 1.42MB
lucene-sandbox-6.4.1.jar 188KB
lucene-core-6.4.1.jar 2.53MB
lucene-misc-6.4.1.jar 152KB
jopt-simple-5.0.2.jar 76KB
jackson-dataformat-cbor-2.8.6.jar 50KB
lucene-join-6.4.1.jar 147KB
transport-5.3.0.jar 7KB
netty-codec-4.1.7.Final.jar 301KB
httpasyncclient-4.1.2.jar 173KB
lucene-queries-6.4.1.jar 225KB
netty-common-4.1.7.Final.jar 670KB
lucene-suggest-6.4.1.jar 241KB
netty-handler-4.1.7.Final.jar 319KB
commons-codec-1.10.jar 278KB
HdrHistogram-2.1.6.jar 107KB
httpcore-nio-4.4.5.jar 348KB
netty-resolver-4.1.7.Final.jar 29KB
snakeyaml-1.15.jar 263KB
t-digest-3.0.jar 49KB
netty-buffer-4.1.7.Final.jar 253KB
transport-netty4-client-5.3.0.jar 77KB
lucene-backward-codecs-6.4.1.jar 85KB
lucene-grouping-6.4.1.jar 105KB
compiler-0.9.3.jar 98KB
netty-codec-http-4.1.7.Final.jar 532KB
log4j-core-2.7.jar 1.24MB
rest-5.3.0.jar 34KB
jna-4.2.2.jar 1.08MB
httpcore-4.4.5.jar 320KB
lucene-highlighter-6.4.1.jar 225KB
percolator-client-5.3.0.jar 99KB
reindex-client-5.3.0.jar 95KB
lucene-memory-6.4.1.jar 45KB
lang-mustache-client-5.3.0.jar 67KB
jackson-core-2.8.6.jar 275KB
httpclient-4.5.2.jar 719KB
log4j-api-2.7.jar 214KB
netty-transport-4.1.7.Final.jar 417KB
transport-netty3-client-5.3.0.jar 79KB
commons-logging-1.1.3.jar 61KB
netty-3.10.6.Final.jar 1.23MB
joda-time-2.9.5.jar 617KB
lucene-queryparser-6.4.1.jar 395KB
jackson-dataformat-smile-2.8.6.jar 72KB
jackson-dataformat-yaml-2.8.6.jar 40KB
lucene-spatial-6.4.1.jar 55KB
securesm-1.1.jar 7KB
elasticsearch-5.3.0.jar 9.37MB
test-classes
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 664B
org.eclipse.core.resources.prefs 57B
pom.xml 1KB
.classpath 677B
bin
共 67 条
- 1
资源评论
- spookssos2018-08-17感谢楼主分享,很不错,非常好用,
- o3style2017-12-13这个很好用,简单
qq_39015533
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于CarNet实现裂缝检测python源码+文档说明+数据+图片(课程设计)
- 课程设计-基于耐火材料裂缝剥落检测python源码+课件
- 基于OpenCV的视频道路车道检测python源码+文档说明+实验演示+图片+使用方法(高分毕业设计)
- 基于OpenCV的案例:图像边缘、角点和轮廓检测,图像分割,图像增强;图片拼接;运动目标检测,颜色直方图比较,三帧帧差法,抠图
- SmartPlug-html大一笔记
- SmartPlug-proteusdemo
- Preliminary Findings on Handmade Rattan Baby Crib andBassinet Designs Regarding.zip
- aveebfq_v1.2.83_downyi.com.apk
- 基于有机发光二极管(OLED)的建模优化算法的matlab仿真源码+数据+文档说明+项目说明(高分课程设计)
- hash01-test.c 本人哈希表(一)的示例代码,仅供参考!
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功