4.2.9预发布版本,支持elasticsearch6.3.1 sql特性
通过 实现对elasticsearch6.3.1 sql的支持。
<property name="elasticEndpoints">
<list>
<bean class="org.sagacity.sqltoy.config.model.ElasticEndpoint">
<constructor-arg value="http://ip:9200" />
<property name="id" value="default" />
<!-- 6.3.x 版本支持xpack sql查询-->
<property name="enableSql" value="true" />
<!-- <property name="username" value="" />
<property name="password" value="" /> -->
</bean>
</list>
</property>
用法(原本通过elasticsearch-sql插件实现,语法保持不变):
<eql id="sys_elastic_test" fields="chineseName,price,trademarkId">
<value>
<![CDATA[
select * from goods_index
where 1=1
#[and chineseName =matchPhrase(:keyword)]
#[and manufacturerName =matchPhrase(:keyword2)]
#[and trademarkName =matchPhrase(:keyword3)]
#[and goodsCateId in (:goodsCateIds)]
#[and transactionType =:transactionType]
#[and trademarkId =:trademarkId]
#[and uom =:uom]
#[and :endPrice >=price]
#[and price >=:startPrice]
#[@if(:priceSort==1 && :transactionSort==1) order by price desc,days desc,upTime desc]
#[@if(:priceSort==0 && :transactionSort==0) order by price asc,days asc,upTime desc]
#[@if(:priceSort==1 && :transactionSort==0) order by price asc,days asc,upTime desc]
#[@if(:priceSort==0 && :transactionSort==1) order by price asc,days asc,upTime desc]
]]>
</value>
</eql>
调用方式:
public List findESBySql(OrganInfoVO organInfoVO) throws Exception {
return elastic().sql("sys_elastic_test").entity(organInfoVO).find();
}
public PaginationModel findESPageBySql(PaginationModel pageModel, GoodsParam goodsParam)
throws Exception {
return elastic().sql("query_goods").entity(goodsParam).resultType(Goods.class).findPage(pageModel);
}