Quick Start
Introduce Elasticsearch Bboss:
- A highlevel rest client.
- A high performence o/r mapping rest client.
- A dsl and sql rest client.
First add the maven dependency of BBoss to your pom.xml:
If it’s a spring boot project, you can replace the Maven coordinate above with the following Maven coordinate:
<groupId>com.bbossgroups.plugins</groupId>
<artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
<version>5.5.3</version>
</dependency>
If the HTTPS protocol is on, add the https protocol header to the elasticsearch address:
elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282
If x-pack or searchguard security authentication is enabled, configure the account and password with the following two properties in application.properties:
And last create a jsp file named testElasticsearch.jsp :
<%@ page import="org.frameworkset.elasticsearch.ElasticSearchHelper" %>
<%@ page import="org.frameworkset.elasticsearch.client.ClientInterface" %>
<%@ page import="org.frameworkset.elasticsearch.entity.ESDatas" %>
<%@ page import="org.frameworkset.elasticsearch.scroll.ScrollHandler" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.frameworkset.common.poolman.SQLExecutor" %>
<%@ page language="java" pageEncoding="UTF-8"%>
ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
//get elasticsearch cluster state
//check indice twitter and index type tweet exist or not.
boolean exist1 = clientUtil.existIndiceType("twitter","tweet");
out.println("twitter tweet type exist:"+exist1);
//check indice twitter exist or not
exist1 = clientUtil.existIndice("twitter");
out.println("twitter exist:"+exist1);
//count documents in indice twitter
long count = clientUtil.countAll("twitter");
out.println(count);
//Get All documents of indice twitter,DEFAULT_FETCHSIZE is 5000
ESDatas<Map> esDatas = clientUtil.searchAll("twitter", Map.class);
//Get All documents of indice twitter,Set fetchsize to 10000, Using ScrollHandler to process each batch of datas.
public void handle(ESDatas<Map> esDatas) throws Exception {
System.out.println("TotalSize:"+esDatas.getTotalSize());
if(dataList != null) {
System.out.println("dataList.size:" + dataList.size());
}
else
{
System.out.println("dataList.size:0");
}
//do something other such as do a db query.
//SQLExecutor.queryList(Map.class,"select * from td_sm_user");
}
},Map.class);
//Use slice parallel scoll query all documents of indice twitter by 2 thread tasks. DEFAULT_FETCHSIZE is 5000
//You can also use ScrollHandler to process each batch of datas on your own.
esDatas = clientUtil.searchAllParallel("twitter", Map.class,2);
out.println("searchAllParallel:ok");
The Web demo github url:
bboss elasticsearch document: