python elasticsearch orm_Elasticsearch SQL ORM查询案例介绍

bboss ES SQL是针对es jdbc的替代解决方案

the best elasticsearch highlevel java rest api-----bboss

bboss 提供一组sql和fetchQuery API,可替代官方es jdbc模块;采用bboss即可拥有bboss的客户端自动发现和容灾能力、对es、jdk、spring boot的兼容性能力,又可以拥有es jdbc的所有功能,同时还解决了因为引入es jdbc导致项目对es版本的强依赖和兼容性问题,参考demo:

目前官方es sql提供的功能有限,也可以在bboss中使用Elasticsearch-sql插件提供的功能,下面有专门的章节介绍。

本文详细说明上面的案例:

集合orm查询

单文orm档查询

fetchsize orm查询

1 orm查询

1.1 定义orm查询的实体bean

package org.bboss.elasticsearchtest.sql;

import com.frameworkset.orm.annotation.Column;

import java.util.Date;

public class DocObject {

private int isnew;

private Date createtime;

private String content;

private int documentId;

private int channelId;

/**

* 通过column指定索引文档和对象属性的映射关系

* 通过column注解还可以指定日期格式和时区信息

* @Column(name="docInfo.author",dataformat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",timezone = "Etc/UTC",locale = "zh")

*

*/

@Column(name="docInfo.author")

private String docInfoAuthor;

public int getIsnew() {

return isnew;

}

public void setIsnew(int isnew) {

this.isnew = isnew;

}

public Date getCreatetime() {

return createtime;

}

public void setCreatetime(Date createtime) {

this.createtime = createtime;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

public int getDocumentId() {

return documentId;

}

public void setDocumentId(int documentId) {

this.documentId = documentId;

}

public int getChannelId() {

return channelId;

}

public void setChannelId(int channelId) {

this.channelId = channelId;

}

public String getDocInfoAuthor() {

return docInfoAuthor;

}

public void setDocInfoAuthor(String docInfoAuthor) {

this.docInfoAuthor = docInfoAuthor;

}

}

实体定义说明:

通过column指定索引文档和对象属性的映射关系,指定日期格式和时区信息,示例如下:

@Column(name="docInfo.author")

private String docInfoAuthor;

指定属性的映射关系、日期格式和时区信息,示例如下:

@Column(name="docInfo.author",dataformat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",timezone = "Etc/UTC",locale = "zh")

执行orm查询

以rest sql api为例来介绍es 6.3.0的sql orm查询功能

package org.bboss.elasticsearchtest.sql;

import org.frameworkset.elasticsearch.ElasticSearchHelper;

import org.frameworkset.elasticsearch.client.ClientInterface;

import org.frameworkset.elasticsearch.entity.sql.SQLRestResponse;

import org.frameworkset.elasticsearch.entity.sql.SQLRestResponseHandler;

import org.junit.Test;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**

* 以rest sql api为例来介绍es 6.3.0的sql orm查询功能

*/

public class SQLOrmTest {

/**

* 代码中的sql检索,返回Map类型集合,亦可以返回自定义的对象集合

*/

@Test

public void testDemoQuery(){

ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();

List json = clientUtil.sql(Map.class,"{\"query\": \"SELECT * FROM demo\

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值