更新
根据条件更新某个字段
String tags = params.get("tags").toString();
String ip = params.get("ip").toString();
Date date = new Date();
String start = DateUtil.getDayByDeal(date, -30, "yyyy-MM-dd") + " 00:00:00";
String end = DateUtil.getDayByDeal(date, 0, "yyyy-MM-dd") + " 23:59:59";
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
boolQueryBuilder.must(QueryBuilders.termQuery("destIp", ip));
UpdateByQueryAction.INSTANCE.newRequestBuilder(transportClient)
.source("sflows")
.filter(boolQueryBuilder)
.script(new Script(ScriptType.INLINE, "painless", "ctx._source.business='" + tags + "'", Collections.EMPTY_MAP))
.abortOnVersionConflict(false)
.get();
根据条件更新多个字段
if (flag.get("flag").toString().equals("1")) {
String source = "";
if (list.get(i).getType() == 1) {
boolQueryBuilder.must(QueryBuilders.termQuery("srcIp", list.get(i).getIp()));
source = "ctx._source.srcBusiness='" + list.get(i).getBusiness() + "'" + ";ctx._source.lineNum='" + list.get(i).getLineNum() + "'";
}
else {
boolQueryBuilder.must(QueryBuilders.termQuery("destIp", list.get(i).getIp()));
source = "ctx._source.business='" + list.get(i).getBusiness() + "'" + ";ctx._source.lineNum='" + list.get(i).getLineNum() + "'";
}
UpdateByQueryAction.INSTANCE.newRequestBuilder(transportClient)
.source("sflows")
.filter(boolQueryBuilder)
.script(new Script(ScriptType.INLINE, "painless", source, Collections.EMPTY_MAP))
.abortOnVersionConflict(false)
.get();
查询
根据时间聚合
public Map<String, Object> getData(Map<String, Object> params) {
int type = Integer.parseInt(params.get("type").toString());
Date date = new Date();
int x = 1;
String start = "";
String end = getDayByDeal(date, -1, "yyyy-MM-dd") + " 23:59:59";
if (type == 2) {
start = getDayByDeal(date, -1, "yyyy-MM-dd") + " 00:00:00";
} else if (type == 3) {
start = getDayByDeal(date, -7, "yyyy-MM-dd") + " 00:00:00";
} else if (type == 4) {
start = getDayByDeal(date, -30, "yyyy-MM-dd") + " 00:00:00";
} else {
start = getTimeByDeal(date, -2);
end = formatTime(date, "yyyy-MM-dd HH:mm:ss");
x = 15;
}
return getLineLoss(type, start, end, x);
}
public Map<String, Object> getLineLoss(int type, String start, String end, int x) {
Map<String, Object> result = new HashMap<>();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
boolQueryBuilder.must(QueryBuilders.existsQuery("dropped_packets"));
DateHistogramInterval dateHistogramInterval = getDateHistogramInterval(type, x);
AggregationBuilder timeAggregation = AggregationBuilders.dateHistogram("agg").field("createDate").format("yyyy-MM-dd HH:mm:ss")
.dateHistogramInterval(dateHistogramInterval).minDocCount(0L).extendedBounds(new ExtendedBounds(start, end));
if (type > 2) {
timeAggregation = AggregationBuilders.dateHistogram("agg").field("createDate").format("yyyy-MM-dd")
.dateHistogramInterval(dateHistogramInterval).minDocCount(0L).extendedBounds(new ExtendedBounds(start.substring(0, 10), end.substring(0, 10)));
}
MaxAggregationBuilder maxLoss = AggregationBuilders.max("maxLoss").field("dropped_packets");
timeAggregation.subAggregation(maxLoss);
SearchResponse response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(timeAggregation).setQuery(boolQueryBuilder).execute().actionGet();
Aggregations aggregations = response.getAggregations();
Histogram histogram = aggregations.get("agg");
List<String> timeList = new ArrayList<>();
List<String> list = new ArrayList<>();
double loss = 0.0;
result.put("maxDate", "暂无");
result.put("maxLoss", loss);
if (histogram.getBuckets().size() > 0) {
for (Histogram.Bucket entry : histogram.getBuckets()) {
timeList.add(entry.getKeyAsString());
Max max = entry.getAggregations().get("maxLoss");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double maxLen = max.getValue();
if (maxLen.equals(Double.NEGATIVE_INFINITY)) {
maxLen = 0.0;
}
list.add(maxLen + "");
if (maxLen > loss) {
result.put("maxLoss", maxLen);
result.put("maxDate", entry.getKeyAsString());
loss = maxLen;
}
} else {
list.add("0.0");
}
}
}
result.put("timeList", timeList);
result.put("seriesData", list);
return result;
}
private DateHistogramInterval getDateHistogramInterval(int dateType, int x) {
if (dateType == 1) {
return DateHistogramInterval.seconds(x);
} else if (dateType == 2) {
return DateHistogramInterval.hours(x);
} else {
return DateHistogramInterval.days(x);
}
}
public double twoDouble(Double value) {
BigDecimal bg = new BigDecimal(value);
double doubleValue = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return doubleValue;
}
public String nonScientificNotation(String num) {
Pattern pattern = Pattern.compile("[0-9]*.[0-9]*E[0-9]*");
Matcher match = pattern.matcher(num);
if (match.matches()) {
BigDecimal decimal = new BigDecimal(num);
num = decimal.toPlainString();
}
return num;
}
public static String getTimeByDeal(Date date, int hour) {
SimpleDateFormat sdf = new SimpleDateFormat(FULL_ST_FORMAT);
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.HOUR_OF_DAY, hour);
return sdf.format(c.getTime());
}
public static String getDayByDeal(Date date, int day, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE, day);
return sdf.format(c.getTime());
}
根据某个字段分组,count计数
public Map<String, Object> getPie(String start, String end) {
Map<String, Object> result = new HashMap<>();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
TermsAggregationBuilder business = AggregationBuilders.terms("business").field("business").size(Integer.MAX_VALUE);
ValueCountAggregationBuilder valueCountAggregationBuilder = AggregationBuilders.count("business").field("business");
business.subAggregation(valueCountAggregationBuilder);
SearchResponse response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(business).setQuery(boolQueryBuilder).execute().actionGet();
Aggregations aggregations = response.getAggregations();
StringTerms stringTerms = aggregations.get("business");
List<Map<String, Object>> data = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
if (stringTerms.getBuckets().size() > 0) {
for (StringTerms.Bucket terms : stringTerms.getBuckets()) {
map.put("legendname", terms.getKey().toString());
map.put("name", terms.getKey().toString());
InternalValueCount internalValueCount = terms.getAggregations().get("business");
map.put("value", internalValueCount.getValue());
data.add(map);
map = new HashMap<>();
}
}
result.put("data", data);
return result;
}
Top5
public Map<String, Object> queryTop5List(int type, String start, String end, int x) {
Map<String, Object> result = new HashMap<>();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
boolQueryBuilder.must(QueryBuilders.existsQuery("destIp"));
TermsAggregationBuilder destIp = AggregationBuilders.terms("destIp").field("destIp").size(Integer.MAX_VALUE);
TermsAggregationBuilder srcIp = AggregationBuilders.terms("srcIp").field("srcIp").size(1);
TermsAggregationBuilder typeOfProtocal = AggregationBuilders.terms("type1").field("type1").size(1);
MaxAggregationBuilder maxTotalLen = AggregationBuilders.max("maxTotalLen").script(new Script(ScriptType.INLINE, "expression", "(doc['totalLen'].value)", new HashMap<>()));
MaxAggregationBuilder maxSamplePool = AggregationBuilders.max("maxSamplePool").field("sample_pool");
MaxAggregationBuilder maxSamplingRate = AggregationBuilders.max("maxSamplingRate").field("sampling_rate");
ValueCountAggregationBuilder valueCountAggregationBuilder = AggregationBuilders.count("count").field("destIp");
TermsAggregationBuilder business = AggregationBuilders.terms("business").field("business").size(1);
TermsAggregationBuilder createDate = AggregationBuilders.terms("createDate").field("createDate").size(1);
destIp.subAggregation(srcIp);
destIp.subAggregation(typeOfProtocal);
destIp.subAggregation(maxTotalLen);
destIp.subAggregation(maxSamplePool);
destIp.subAggregation(maxSamplingRate);
destIp.subAggregation(valueCountAggregationBuilder);
destIp.subAggregation(business);
destIp.subAggregation(createDate);
destIp.size(5);
destIp.order(BucketOrder.compound(BucketOrder.aggregation("maxTotalLen", false)));
SearchResponse response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(destIp).setQuery(boolQueryBuilder).setSize(5).execute().actionGet();
Aggregations aggregations = response.getAggregations();
StringTerms destIpTerms = aggregations.get("destIp");
SearchHits searchHits = response.getHits();
long total = searchHits.totalHits;
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
double maxRate = 0.0;
if (destIpTerms.getBuckets().size() > 0) {
for (StringTerms.Bucket terms : destIpTerms.getBuckets()) {
map = new HashMap<>();
map.put("destIp", terms.getKeyAsString());
StringTerms stringTerms = terms.getAggregations().get("srcIp");
for (StringTerms.Bucket src : stringTerms.getBuckets()) {
map.put("srcIp", src.getKeyAsString());
}
stringTerms = terms.getAggregations().get("business");
for (StringTerms.Bucket src : stringTerms.getBuckets()) {
map.put("business", src.getKeyAsString());
}
stringTerms = terms.getAggregations().get("type1");
for (StringTerms.Bucket src : stringTerms.getBuckets()) {
map.put("type", src.getKeyAsString());
}
Max max = terms.getAggregations().get("maxTotalLen");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double d = max.getValue();
if (d.equals(Double.NEGATIVE_INFINITY)) {
d = 0.0;
}
map.put("totalLen", d);
} else {
map.put("totalLen", 0.0);
}
max = terms.getAggregations().get("maxSamplePool");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double d = max.getValue();
if (d.equals(Double.NEGATIVE_INFINITY)) {
d = 0.0;
}
map.put("samplePool", nonScientificNotation(String.valueOf(d)));
} else {
map.put("samplePool", 0.0);
}
InternalValueCount internalValueCount = terms.getAggregations().get("count");
Double rate = twoDouble(((double) internalValueCount.getValue() / (double) total) * 100);
if (rate > maxRate) {
result.put("maxRate", rate);
result.put("maxIp", map.get("destIp"));
result.put("maxTotalLen", map.get("totalLen"));
LongTerms longTerms = terms.getAggregations().get("createDate");
for (LongTerms.Bucket src : longTerms.getBuckets()) {
result.put("maxDate", src.getKeyAsString());
}
max = terms.getAggregations().get("maxSamplingRate");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double d = max.getValue();
if (d.equals(Double.NEGATIVE_INFINITY)) {
d = 0.0;
}
result.put("maxSamplingRate", nonScientificNotation(String.valueOf(d)));
} else {
result.put("maxSamplingRate", 0.0);
}
maxRate = rate;
}
map.put("rate", rate);
list.add(map);
}
}
result.put("dataTable", list);
return result;
}
根据字段以及时间分组
public Map<String, Object> getLineTop5(int type, String start, String end, int x) {
Map<String, Object> result = new HashMap<>();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
boolQueryBuilder.must(QueryBuilders.existsQuery("destIp"));
TermsAggregationBuilder destIp = AggregationBuilders.terms("destIp").field("destIp").size(Integer.MAX_VALUE);
DateHistogramInterval dateHistogramInterval = getDateHistogramInterval(type, x);
AggregationBuilder timeAggregation = AggregationBuilders.dateHistogram("agg").field("createDate").format("yyyy-MM-dd HH:mm:ss")
.dateHistogramInterval(dateHistogramInterval).minDocCount(0L).extendedBounds(new ExtendedBounds(start, end));
if (type > 2) {
timeAggregation = AggregationBuilders.dateHistogram("agg").field("createDate").format("yyyy-MM-dd")
.dateHistogramInterval(dateHistogramInterval).minDocCount(0L).extendedBounds(new ExtendedBounds(start.substring(0, 10), end.substring(0, 10)));
}
MaxAggregationBuilder maxTotalLen = AggregationBuilders.max("maxTotalLen").script(new Script(ScriptType.INLINE, "expression", "(doc['totalLen'].value)", new HashMap<>()));
timeAggregation.subAggregation(maxTotalLen);
destIp.subAggregation(timeAggregation);
destIp.subAggregation(maxTotalLen);
destIp.size(5);
destIp.order(BucketOrder.compound(BucketOrder.aggregation("maxTotalLen", false)));
SearchResponse response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(destIp).addAggregation(timeAggregation)
.setQuery(boolQueryBuilder).setSize(5).execute().actionGet();
Aggregations aggregations = response.getAggregations();
StringTerms stringTerms = aggregations.get("destIp");
List<String> timeList = new ArrayList<>();
List<String> ipList = new ArrayList<>();
List<List<String>> dataList = new ArrayList<>();
if (stringTerms.getBuckets().size() > 0) {
for (StringTerms.Bucket terms : stringTerms.getBuckets()) {
ipList.add(terms.getKey().toString());
Histogram histogram = terms.getAggregations().get("agg");
List<String> list = new ArrayList<>();
timeList = new ArrayList<>();
if (histogram.getBuckets().size() > 0) {
for (Histogram.Bucket entry : histogram.getBuckets()) {
timeList.add(entry.getKeyAsString());
Max max = entry.getAggregations().get("maxTotalLen");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double maxLen = max.getValue();
if (maxLen.equals(Double.NEGATIVE_INFINITY)) {
maxLen = 0.0;
}
list.add(maxLen + "");
} else {
list.add("0.0");
}
}
}
dataList.add(list);
}
}
result.put("timeList", timeList);
result.put("legend", ipList);
result.put("seriesData", dataList);
return result;
}
分组后分页
public EsPage queryMore(Map<String, Object> params) throws Exception {
int type = Integer.parseInt(params.get("type").toString());
Date date = new Date();
int x = 1;
String start = "";
String end = getDayByDeal(date, -1, "yyyy-MM-dd") + " 23:59:59";
if (type == 2) {
start = getDayByDeal(date, -1, "yyyy-MM-dd") + " 00:00:00";
} else if (type == 3) {
start = getDayByDeal(date, -7, "yyyy-MM-dd") + " 00:00:00";
} else if (type == 4) {
start = getDayByDeal(date, -30, "yyyy-MM-dd") + " 00:00:00";
} else {
start = getTimeByDeal(date, -2);
end = formatTime(date, "yyyy-MM-dd HH:mm:ss");
}
String ipQuery = params.get("ip").toString();
String destIpQuery = params.get("destIp").toString();
String protocolQuery = params.get("protocol").toString();
String businessQuery = params.get("business").toString();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd HH:mm:ss").lte(end).gte(start));
boolQueryBuilder.must(QueryBuilders.existsQuery("destIp"));
if (!StringUtils.isEmpty(ipQuery)) {
boolQueryBuilder.must(QueryBuilders.termQuery("ip", ipQuery));
}
if (!StringUtils.isEmpty(destIpQuery)) {
boolQueryBuilder.must(QueryBuilders.termQuery("destIp", destIpQuery));
}
if (!StringUtils.isEmpty(protocolQuery)) {
boolQueryBuilder.must(QueryBuilders.termQuery("type1", protocolQuery));
}
if (!StringUtils.isEmpty(businessQuery)) {
boolQueryBuilder.must(QueryBuilders.termQuery("business", businessQuery));
}
TermsAggregationBuilder destIp = AggregationBuilders.terms("destIp").field("destIp").size(Integer.MAX_VALUE);
TermsAggregationBuilder ip = AggregationBuilders.terms("ip").field("ip").size(1);
TermsAggregationBuilder srcIp = AggregationBuilders.terms("srcIp").field("srcIp").size(1);
TermsAggregationBuilder typeOfProtocal = AggregationBuilders.terms("type1").field("type1").size(1);
MaxAggregationBuilder maxTotalLen = AggregationBuilders.max("maxTotalLen").field("totalLen");
MaxAggregationBuilder maxSamplePool = AggregationBuilders.max("maxSamplePool").field("sample_pool");
MaxAggregationBuilder maxSamplingRate = AggregationBuilders.max("maxSamplingRate").field("sampling_rate");
ValueCountAggregationBuilder valueCountAggregationBuilder = AggregationBuilders.count("count").field("destIp");
TermsAggregationBuilder business = AggregationBuilders.terms("business").field("business").size(1);
destIp.subAggregation(ip);
destIp.subAggregation(srcIp);
destIp.subAggregation(typeOfProtocal);
destIp.subAggregation(maxTotalLen);
destIp.subAggregation(maxSamplePool);
destIp.subAggregation(maxSamplingRate);
destIp.subAggregation(valueCountAggregationBuilder);
destIp.subAggregation(business);
SearchResponse response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(destIp).setQuery(boolQueryBuilder).execute().actionGet();
Aggregations aggregations = response.getAggregations();
Map<String, Aggregation> aggregationMap = aggregations.asMap();
StringTerms stringTerms = (StringTerms) aggregationMap.get("destIp");
List<StringTerms.Bucket> bucketsList = stringTerms.getBuckets();
int total = bucketsList.size();
int startIndex = (Integer.parseInt(params.get("pageNum").toString()) - 1) * Integer.parseInt(params.get("pageSize").toString());
int endIndex = Integer.parseInt(params.get("pageNum").toString()) * Integer.parseInt(params.get("pageSize").toString());
response = transportClient.prepareSearch("sflows").setTypes("sflow")
.addAggregation(destIp.size(endIndex)).setQuery(boolQueryBuilder).execute().actionGet();
aggregations = response.getAggregations();
aggregationMap = aggregations.asMap();
stringTerms = (StringTerms) aggregationMap.get("destIp");
bucketsList = stringTerms.getBuckets();
int i = 0;
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
if (bucketsList.size() > 0) {
for (Terms.Bucket entry : bucketsList) {
i++;
if (i < startIndex) {
continue;
}
if (i > endIndex) {
break;
}
map.put("destIp", entry.getKeyAsString());
StringTerms stringTerms1 = entry.getAggregations().get("srcIp");
for (StringTerms.Bucket src : stringTerms1.getBuckets()) {
map.put("srcIp", src.getKeyAsString());
}
stringTerms1 = entry.getAggregations().get("ip");
for (StringTerms.Bucket src : stringTerms1.getBuckets()) {
map.put("ip", src.getKeyAsString());
}
stringTerms1 = entry.getAggregations().get("business");
for (StringTerms.Bucket src : stringTerms1.getBuckets()) {
map.put("business", src.getKeyAsString());
}
stringTerms1 = entry.getAggregations().get("type1");
for (StringTerms.Bucket src : stringTerms1.getBuckets()) {
map.put("type", src.getKeyAsString());
}
Max max = entry.getAggregations().get("maxTotalLen");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double d = max.getValue();
if (d.equals(Double.NEGATIVE_INFINITY)) {
d = 0.0;
}
map.put("totalLen", d);
} else {
map.put("totalLen", 0.0);
}
max = entry.getAggregations().get("maxSamplePool");
if (max != null && !"-Infinity".equals(String.valueOf(max.getValue()))) {
Double d = max.getValue();
if (d.equals(Double.NEGATIVE_INFINITY)) {
d = 0.0;
}
map.put("samplePool", nonScientificNotation(String.valueOf(d)));
} else {
map.put("samplePool", 0.0);
}
InternalValueCount internalValueCount = entry.getAggregations().get("count");
Double rate = twoDouble(((double) internalValueCount.getValue() / (double) total) * 100);
map.put("rate", rate);
list.add(map);
map = new HashMap<>();
}
}
EsPage esPage = new EsPage();
esPage.setPageSize(Integer.parseInt(params.get("pageSize").toString()));
esPage.setCurrentPage(Integer.parseInt(params.get("pageNum").toString()));
esPage.setRecordCount(total);
esPage.setRecordList(list);
return esPage;
}
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Data
@ToString
public class EsPage {
@JsonProperty("pageIndex")
private int currentPage;
@JsonProperty("pageSize")
private int pageSize;
@JsonProperty("total")
private int recordCount;
@JsonProperty("data")
private Object recordList;
@JsonProperty("pageCount")
private int pageCount;
@JsonProperty("beginPageIndex")
private int beginPageIndex;
@JsonProperty("endPageIndex")
private int endPageIndex;
public EsPage(int currentPage, int pageSize, int recordCount, Object recordList) {
this.currentPage = currentPage;
this.pageSize = pageSize;
this.recordCount = recordCount;
this.recordList = recordList;
pageCount = (recordCount + pageSize - 1) / pageSize;
if (pageCount <= 10) {
beginPageIndex = 1;
endPageIndex = pageCount;
}
else {
beginPageIndex = currentPage - 4;
endPageIndex = currentPage + 5;
if (beginPageIndex < 1) {
beginPageIndex = 1;
endPageIndex = 10;
}
if (endPageIndex > pageCount) {
endPageIndex = pageCount;
beginPageIndex = pageCount - 10 + 1;
}
}
}
public EsPage() {
}
}
模糊查询/自带的分页
public PagerModel pageQuery(Integer pageNo, Integer pageSize, Map<String, Object> params) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
for (String key : params.keySet()) {
String value = params.get(key).toString();
if (!StringUtils.isEmpty(value)) {
if (key.equals("start")) {
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd").gte(value));
} else if (key.equals("end")) {
boolQueryBuilder.must(QueryBuilders.rangeQuery("createDate").format("yyyy-MM-dd").lte(value));
} else if (key.equals("keyword")) {
BoolQueryBuilder shouldQueryBuilder = QueryBuilders.boolQuery();
value = "*" + value + "*";
shouldQueryBuilder.should(QueryBuilders.wildcardQuery("title", value.toLowerCase()));
shouldQueryBuilder.should(QueryBuilders.wildcardQuery("label", value.toLowerCase()));
shouldQueryBuilder.should(QueryBuilders.wildcardQuery("question", value.toLowerCase()));
boolQueryBuilder.must(shouldQueryBuilder);
} else {
boolQueryBuilder.must(QueryBuilders.termQuery(key, value));
}
}
}
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder().withTypes(HOSPITAL)
.withQuery(boolQueryBuilder).withPageable(PageRequest.of(pageNo, pageSize)).withSort((SortBuilders.fieldSort("lastReplyTime").order(SortOrder.DESC)));
Page<HospitalBean> items = dao.search(builder.build());
PagerModel model = new PagerModel();
model.setRows(items.getContent());
model.setTotalCount(items.getTotalElements());
return model;
}