Quick Start

    Introduce Elasticsearch Bboss:

    1. A highlevel rest client.
    2. A high performence o/r mapping rest client.
    3. 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:

    1. <groupId>com.bbossgroups.plugins</groupId>
    2. <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
    3. <version>5.5.3</version>
    4. </dependency>

    If the HTTPS protocol is on, add the https protocol header to the elasticsearch address:

    1. 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 :

    1. <%@ page import="org.frameworkset.elasticsearch.ElasticSearchHelper" %>
    2. <%@ page import="org.frameworkset.elasticsearch.client.ClientInterface" %>
    3. <%@ page import="org.frameworkset.elasticsearch.entity.ESDatas" %>
    4. <%@ page import="org.frameworkset.elasticsearch.scroll.ScrollHandler" %>
    5. <%@ page import="java.util.List" %>
    6. <%@ page import="java.util.Map" %>
    7. <%@ page import="com.frameworkset.common.poolman.SQLExecutor" %>
    8. <%@ page language="java" pageEncoding="UTF-8"%>
    9. ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
    10. //get elasticsearch cluster state
    11. //check indice twitter and index type tweet exist or not.
    12. boolean exist1 = clientUtil.existIndiceType("twitter","tweet");
    13. out.println("twitter tweet type exist:"+exist1);
    14. //check indice twitter exist or not
    15. exist1 = clientUtil.existIndice("twitter");
    16. out.println("twitter exist:"+exist1);
    17. //count documents in indice twitter
    18. long count = clientUtil.countAll("twitter");
    19. out.println(count);
    20. //Get All documents of indice twitter,DEFAULT_FETCHSIZE is 5000
    21. ESDatas<Map> esDatas = clientUtil.searchAll("twitter", Map.class);
    22. //Get All documents of indice twitter,Set fetchsize to 10000, Using ScrollHandler to process each batch of datas.
    23. public void handle(ESDatas<Map> esDatas) throws Exception {
    24. System.out.println("TotalSize:"+esDatas.getTotalSize());
    25. if(dataList != null) {
    26. System.out.println("dataList.size:" + dataList.size());
    27. }
    28. else
    29. {
    30. System.out.println("dataList.size:0");
    31. }
    32. //do something other such as do a db query.
    33. //SQLExecutor.queryList(Map.class,"select * from td_sm_user");
    34. }
    35. },Map.class);
    36. //Use slice parallel scoll query all documents of indice twitter by 2 thread tasks. DEFAULT_FETCHSIZE is 5000
    37. //You can also use ScrollHandler to process each batch of datas on your own.
    38. esDatas = clientUtil.searchAllParallel("twitter", Map.class,2);
    39. out.println("searchAllParallel:ok");

    The Web demo github url:

    bboss elasticsearch document: