ElasticSearch Bboss + SpringBoot

maven引入bboss包

        <!-- https://mvnrepository.com/artifact/com.bbossgroups.plugins/bboss-elasticsearch-spring-boot-starter -->
        <dependency>
            <groupId>com.bbossgroups.plugins</groupId>
            <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
            <version>6.2.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.bbossgroups.plugins/bboss-elasticsearch-rest-jdbc -->
        <dependency>
            <groupId>com.bbossgroups.plugins</groupId>
            <artifactId>bboss-elasticsearch-rest-jdbc</artifactId>
            <version>6.2.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

application.properties 配置

server.port=8080
spring.main.lazy-initialization=true

spring.elasticsearch.bboss.elasticsearch.rest.hostNames=localhost:9200


@Log4j2
@RequestMapping("product")
@RestController
public class ProductController {

    private BBossESStarter bbossESStarter;

    @Autowired
    public void setBbossESStarter(BBossESStarter bbossESStarter) {
        this.bbossESStarter = bbossESStarter;
    }

    @GetMapping("queryAllUseSearch")
    public ResponseEntity<Result<List<Product>>> queryAllUseSearch() {
        ClientInterface clientInterface = bbossESStarter.getRestClient();

        ESDatas<Product> productESDatas = clientInterface.searchList("es_biz_trade_product/_search", Product.class);
        log.error("TotalSize: {}", productESDatas.getTotalSize());
        log.error("ScrollId: {}", productESDatas.getScrollId());
        log.error("TotalRelation: {}", productESDatas.getTotalRelation());
        return ResultUtils.ok(productESDatas.getDatas());
    }

    @GetMapping("queryAllUseExecuteHttp")
    public ResponseEntity<Result<List<Product>>> queryAllUseExecuteHttp() {
        ClientInterface clientInterface = bbossESStarter.getRestClient();
        String json = clientInterface.executeHttp("/_xpack/sql?format=json", "{\"query\": \"SELECT * FROM es_biz_trade_product\"}", ClientInterface.HTTP_POST);
        return ResultUtils.ok(json);
    }

    @GetMapping("queryAllUseFetchQuery")
    public ResponseEntity<Result<List<Product>>> queryAllUseFetchQuery() {
        ClientInterface clientInterface = bbossESStarter.getRestClient();
        SQLResult<Product> productSQLResult = clientInterface.fetchQuery(Product.class, "{\"query\": \"SELECT * FROM es_biz_trade_product\"}");

        return ResultUtils.ok(productSQLResult.getDatas());
    }

    @GetMapping("queryAllUseSql")
    public ResponseEntity<Result<List<Product>>> queryAllUseSql() {
        ClientInterface clientInterface = bbossESStarter.getRestClient();
        List<Product> productList = clientInterface.sql(Product.class,"{\"query\": \"SELECT * FROM es_biz_trade_product\"}");
        return ResultUtils.ok(productList);
    }
}

model:

@Data
public class Product implements Serializable {

    private long id;
    private String name;
    private double originalPrice;
    private double currentPrice;
}

bboss 配置项目所在源码包:

    bboss-elasticsearch-spring-boot-starter
    org.frameworkset.elasticsearch.boot.BBossESProperties
    org.frameworkset.elasticsearch.boot.BBossESAutoConfiguration

评论

暂无评论