elasticsearch JAVA客户端操作---索引的CURD

源码地址:源码下载点击

索引的创建

	public void addindex01() {
		UserModel user = new UserModel();
		user.setId(1);
		user.setName("李四");
		user.setAge("101");
		user.setSex("1231");
		user.setTel("Tel");
		String jsondata = ESUtils.toJson(user);
		System.out.println("封装的json:"+jsondata);
		IndexResponse res = client.prepareIndex().setIndex("test").setType("test01").setId("14")
				.setSource(jsondata).execute().actionGet();
		
		System.out.println("索引创建成功,版本号:"+res.getVersion());
	}
	
	public void addindex02(int i) {
		UserModel user = new UserModel();
		user.setId(new Random().nextInt(20));
		user.setName("张三_"+new Random().nextInt(10));
		user.setAge("1012");
		 if(new Random().nextInt(20)%2==0){
			 user.setSex("boy");
		 }
		 else{
			 user.setSex("grile");
		 }
		user.setTel("1514414");
		String jsondata = ESUtils.toJson(user);
		System.out.println("封装的json:"+jsondata);
		IndexResponse res = client.prepareIndex().setIndex("test4").setType("test04").setId(String.valueOf(i))
				.setSource(jsondata).execute().actionGet();
		
		System.out.println("索引创建成功,版本号:"+res.getVersion());
	}
删除
	public void del01() {

		DeleteResponse res = client.prepareDelete().setIndex("test2")
				.setType("test02").setId("4").execute().actionGet();
		System.out.println("删除成功");
	}

查询

public void getIndex() {
		GetResponse res = client.prepareGet().setIndex("test")
				.setType("test01").setId("1").execute().actionGet();
		System.out.println(res.getSource());
	}
更改:

  更改就是索引删除之后 在重新建立

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值