es查询合集
Term 精准匹配查询
{
"query": {
"term": {
"jerseyNo": "23"
}
}
}
QueryBuilders.termQuery("jerseyNo.keyword","23")
Terms 批量查询
{
"query": {
"bool": {
"must": [
{
"terms": {
"goods_id": [
1,
2,
3
]
}
}
]
}
}
}
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.termsQuery(fieldName + ".keyword", (List<String>) value));
Wildcard 模糊查询
{
"query": {
"wildcard": {
"teamNameEn": "Ro*s"
}
}
}
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.wildcardQuery(fieldName + ".keyword", ("*" + value + "*")));
Exsit 在特定的字段中查找非空值的文档
{
"query": {
"term": {
"exists": "schoolType"
}
}
}
QueryBuilders.existsQuery("schoolType")
Prefix 查找包含带有指定前缀term的文档
{
"query": {
"prefix": {
"teamNameEn": "Rock"
}
}
}
QueryBuilders.prefixQuery("teamNameEn","Rock")
range范围查询
{
"query": {
"range": {
"playYear": {
"gte": 2,
"lte": 10
}
}
}
}
queryBuilder.must(QueryBuilders.rangeQuery("playYear" + "TimeStamp").gte(startDate).lte(endDate));
Sort 排序查询
{
"query": {
"match": {
"teamNameEn": "Rockets"
}
},
"sort": [
{
"playYear": {
"order": "desc"
}
}
]
}
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.matchQuery("teamNameEn","Rockets"));
sourceBuilder.sort("palyYear", SortOrder.DESC);
Terms Aggregation 根据字段项分组聚合
{
"query": {
"term": {
"teamNameEn": {
"value": "Rockets"
}
}
},
"aggs": {
"aggsAge": {
"terms": {
"field": "age",
"size": 20
}
}
},
"size": 0
}
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermsAggregationBuilder state = AggregationBuilders.terms("age").field("age.keyword").size(200);
searchSourceBuilder.aggregation(termsAggregationBuilder);
searchSourceBuilder.size(0);
System.out.println("********************************************");
System.out.println(searchSourceBuilder);
searchRequest.source(searchSourceBuilder);
es实战以及封装方法
es接收结果对象:EsQueryResultVO
@Builder
@Data
public class EsQueryResultVO<T>{
private List<T> records ;
private long total;
private long size;
private Object[] lastNum;
}
es封装工具:EsUtil
@Slf4j
@Service
public class ESUtil {
@Resource
private RestHighLevelClient client;
public String addData(XContentBuilder content, String index, String id) {
try {
IndexRequest request = new IndexRequest(index).id(id).source(content);
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
id = response.getId();
log.info("索引:{},数据添加,返回码:{},id:{}", index, response.status().getStatus(), id);
} catch (Exception e) {
log.error("添加数据失败,index:{},id:{}", index, id);
}
return id;
}
public String updateData(XContentBuilder content, String index, String id) {
String resultId = null;
try {
UpdateRequest request = new UpdateRequest(index, id).doc(content);
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
UpdateResponse response = client.update(request, RequestOptions.DEFAULT);
resultId = response.getId();
log.info("数据更新,返回码:{},id:{}", response.status().getStatus(), resultId);
} catch (Exception e) {
log.error("数据更新失败,index:{},id:{}", index, id);
}
return resultId;
}
public boolean existsData(String index, String id) {
try {
GetRequest request = new GetRequest(index, id);
boolean isExists = client.exists(request, RequestOptions.DEFAULT);
return isExists;
} catch (Exception e) {
log.error("数据判断是否存在失败,index:{},id:{}", index, id);
}
return false;
}
public String insertBatch(String index, List<EsDTO> list) throws IOException {
String state = null;
BulkRequest request = new BulkRequest();
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
list.forEach(item -> request.add(new IndexRequest(index)
.id(item.getId()).source(JSON.toJSONString(item.getData()), XContentType.JSON)));
try {
BulkResponse bulk = client.bulk(request, RequestOptions.DEFAULT);
if (bulk.hasFailures()) {
throw new TransactionalHandleException(bulk.buildFailureMessage());
}
int status = bulk.status().getStatus();
state = Integer.toString(status);
log.info("索引:{},批量插入{}条数据成功!", index, list.size());
} catch (Exception e) {
log.error("索引:{},批量插入数据失败,异常描述:{}", index, e.getMessage());
throw e;
}
return state;
}
public void deleteByQuery(String index, QueryBuilder builder) {
DeleteByQueryRequest request = new DeleteByQueryRequest(index);
request.setQuery(builder);
request.setBatchSize(1000);
try {
client.deleteByQuery(request, RequestOptions.DEFAULT);
} catch (Exception e) {
log.error("根据条件删除数据失败,index:{}", index);
}
}
public String deleteById(String index, String id) {
String state = null;
DeleteRequest request = new DeleteRequest(index, id);
try {
DeleteResponse response = client.delete(request, RequestOptions.DEFAULT);
int status = response.status().getStatus();
state = Integer.toString(status);
log.info("索引:{},根据id{}删除数据:{}", index, id, JSON.toJSONString(response));
} catch (Exception e) {
log.error("根据id删除数据失败,index:{},id:{}", index, id);
}
return state;
}
public List<Map<String, Object>> searchDataPage(String index, int startPage, int pageSize,
SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchRequest request = new SearchRequest(index);
sourceBuilder.timeout(new TimeValue(120, TimeUnit.SECONDS));
sourceBuilder.explain(true);
sourceBuilder.query(queryBuilder);
sourceBuilder.from((startPage - 1) * pageSize).size(pageSize);
log.info("查询返回条件:" + sourceBuilder.toString());
request.source(sourceBuilder);
try {
SearchResponse searchResponse = client.search(request, RequestOptions.DEFAULT);
TotalHits totalHits = searchResponse.getHits().getTotalHits();
log.info("共查出{}条记录", totalHits);
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
List<Map<String, Object>> sourceList = new ArrayList<>();
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
return sourceList;
}
} catch (Exception e) {
log.error("条件查询索引{}时出错", index);
}
return null;
}
public IPage searchDataPage(String index, Query query,
SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchRequest request = new SearchRequest(index);
sourceBuilder.timeout(new TimeValue(120, TimeUnit.SECONDS));
sourceBuilder.explain(true);
sourceBuilder.query(queryBuilder);
sourceBuilder.from((query.getCurrent() - 1) * query.getSize()).size(query.getSize());
if (StringUtils.isNotEmpty(query.getAscs())) {
sourceBuilder.sort(query.getAscs(), SortOrder.ASC);
}
if (StringUtils.isNotEmpty(query.getDescs())) {
sourceBuilder.sort(query.getDescs(), SortOrder.DESC);
}
log.info("查询返回条件:" + sourceBuilder.toString());
request.source(sourceBuilder);
try {
SearchResponse searchResponse = client.search(request, RequestOptions.DEFAULT);
TotalHits totalHits = searchResponse.getHits().getTotalHits();
log.info("共查出{}条记录", totalHits);
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
List sourceList = new ArrayList<>();
IPage page = Condition.getPage(query);
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
page.setRecords(sourceList);
page.setTotal(totalHits.value);
return page;
}
} catch (Exception e) {
log.error("条件查询索引{}时出错", index);
}
return null;
}
public Map<String, Object> searchOne(String index, String id) {
try {
GetRequest request = new GetRequest(index, id);
GetResponse response = client.get(request, RequestOptions.DEFAULT);
return response.getSourceAsMap();
} catch (Exception e) {
log.error("获取单条失败,index:{},id:{},e={}", index, id, e);
}
return null;
}
public List<Map<String, Object>> searchList(String index, SearchSourceBuilder searchSourceBuilder) {
try {
SearchRequest searchRequest = new SearchRequest(index);
searchSourceBuilder.timeout(new TimeValue(120, TimeUnit.SECONDS));
searchSourceBuilder.explain(true);
searchRequest.source(searchSourceBuilder);
log.info("index={},查询返回条件:" + searchSourceBuilder.toString());
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
List sourceList = new ArrayList<>();
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
return sourceList;
}
} catch (Exception e) {
log.error("根据ids查询失败,index:{},searchSourceBuilder:{}", index, searchSourceBuilder);
}
return null;
}
public EsQueryResultVO searchAfterList(String index, Query query, QueryBuilder queryBuilder, SearchSourceBuilder searchSourceBuilder) {
List<Object> result = new ArrayList<>();
try {
if (StringUtils.isEmpty(index)) {
return EsQueryResultVO.builder().build();
}
SearchRequest searchRequest = new SearchRequest(index);
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.timeout(new TimeValue(100, TimeUnit.SECONDS));
searchSourceBuilder.explain(true);
searchSourceBuilder.size(query.getSize());
if (StringUtils.isNotEmpty(query.getAscs())) {
searchSourceBuilder.sort(query.getAscs(), SortOrder.ASC);
}
if (StringUtils.isNotEmpty(query.getDescs())) {
searchSourceBuilder.sort(query.getDescs(), SortOrder.DESC);
}
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
log.info("index={},查询返回条件={}", index, searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = searchResponse.getHits().getHits();
if (Objects.nonNull(hits) && hits.length > 0) {
for (SearchHit hit : hits) {
result.add(hit.getSourceAsMap());
}
SearchHit[] hits1 = searchResponse.getHits().getHits();
Object[] lastNum = hits1[hits1.length - 1].getSortValues();
return EsQueryResultVO.builder()
.records(result)
.size(query.getSize())
.total(searchResponse.getHits().getTotalHits().value)
.lastNum(lastNum)
.build();
}
} catch (Exception e) {
log.error("根据ids查询失败,index:{},searchSourceBuilder:{}", index, searchSourceBuilder);
}
return EsQueryResultVO.builder().build();
}
public void updateEs(String index, String id, Map<String, Object> params) {
log.info("updateEs开始修改ES数据时间:{};", com.goldnet.core.tool.utils.DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(getRequest(index, id, JSON.toJSONString(params)));
try {
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
if (bulkResponse.hasFailures()) {
for (BulkItemResponse item : bulkResponse.getItems()) {
log.info(">>>>>>updateEs>>>update error, id=" + id + ", msg=" + item.getFailureMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
log.info(">>>>>>updateEs>>>update error, id=" + id + ", error=" + e.getMessage());
}
log.info("updateEs结束修改ES数据时间:{};", com.goldnet.core.tool.utils.DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
}
public void batchUpdateEs(String index, List<String> ids, List<Map<String, Object>> paramsList) {
log.info("batchUpdateEs开始批量修改ES数据时间:{};", DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < ids.size(); i++) {
UpdateRequest updateRequest = getRequest(index, ids.get(i), JSON.toJSONString(paramsList.get(i)));
bulkRequest.add(updateRequest);
}
try {
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
if (bulkResponse.hasFailures()) {
for (BulkItemResponse item : bulkResponse.getItems()) {
log.info(">>>>>>batchUpdateEs>>>update error, id=" + item.getId() + ", msg=" + item.getFailureMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
log.info(">>>>>>batchUpdateEs>>>update error, error=" + e.getMessage());
}
log.info("batchUpdateEs结束批量修改ES数据时间:{};", DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
}
public UpdateRequest getRequest(String index, String id, String json) {
UpdateRequest updateRequest = new UpdateRequest(index, id);
updateRequest.retryOnConflict(3);
updateRequest.docAsUpsert(true);
updateRequest.detectNoop(false);
updateRequest.fetchSource(true);
updateRequest.upsert(json, XContentType.JSON);
updateRequest.doc(json, XContentType.JSON);
return updateRequest;
}
public IPage searchDataDistinctPage(String index, Query query, SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder, String disField) {
SearchRequest request = new SearchRequest(index);
sourceBuilder.timeout(new TimeValue(120, TimeUnit.SECONDS));
sourceBuilder.explain(true);
sourceBuilder.trackTotalHits(true);
sourceBuilder.query(queryBuilder);
sourceBuilder.from((query.getCurrent() - 1) * query.getSize()).size(query.getSize());
if (StringUtils.isNotEmpty(query.getAscs())) {
sourceBuilder.sort(query.getAscs(), SortOrder.ASC);
}
if (StringUtils.isNotEmpty(query.getDescs())) {
sourceBuilder.sort(query.getDescs(), SortOrder.DESC);
}
CollapseBuilder collapseBuilder = new CollapseBuilder(disField + ".keyword");
sourceBuilder.collapse(collapseBuilder);
AggregationBuilder aggregation = AggregationBuilders.cardinality(disField).field(disField + ".keyword");
sourceBuilder.aggregation(aggregation);
log.info("查询返回条件:" + sourceBuilder.toString());
request.source(sourceBuilder);
try {
SearchResponse searchResponse = client.search(request, RequestOptions.DEFAULT);
log.info("response is {}", searchResponse);
Aggregations aggregations = searchResponse.getAggregations();
Cardinality cardinality = aggregations.get(disField);
log.info("共查出{}条记录", cardinality.getValue());
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
List sourceList = new ArrayList<>();
IPage page = Condition.getPage(query);
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
page.setRecords(sourceList);
long size = searchDataDistinctCountPage(index,queryBuilder,disField, (int) cardinality.getValue());
page.setTotal(size);
return page;
}
} catch (Exception e) {
log.error("条件查询索引{}时出错", index);
}
return null;
}
public long searchDataDistinctCountPage(String index, QueryBuilder queryBuilder, String disField, Integer size) {
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
TermsAggregationBuilder termsAggregation = AggregationBuilders.terms("group_by_field")
.field(disField + ".keyword")
.size(size);
searchSourceBuilder.aggregation(termsAggregation);
searchSourceBuilder.size(0);
log.info("查询返回条件:" + searchSourceBuilder.toString());
searchRequest.source(searchSourceBuilder);
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
Terms groupByFieldTerms = searchResponse.getAggregations().get("group_by_field");
long bucketCount = groupByFieldTerms.getBuckets().size();
log.info("汇总去重复统计总数Bucket count: " + bucketCount);
return bucketCount;
}
client.close();
} catch (IOException e) {
e.printStackTrace();
}
return Long.parseLong(size.toString());
}
public int count(String index, Query query, SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchResponse response = getSearchResponse(index, query, sourceBuilder, queryBuilder);
SearchHits hits = response.getHits();
return Integer.parseInt(String.valueOf(hits.getTotalHits().value));
}
private SearchResponse getSearchResponse(String index, Query query, SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchRequest searchRequest = new SearchRequest(index);
sourceBuilder.timeout(new TimeValue(120, TimeUnit.SECONDS));
sourceBuilder.explain(true);
sourceBuilder.trackTotalHits(true);
sourceBuilder.from((query.getCurrent() - 1) * query.getSize()).size(query.getSize());
if (StringUtils.isNotEmpty(query.getAscs())) {
sourceBuilder.sort(query.getAscs(), SortOrder.ASC);
}
if (StringUtils.isNotEmpty(query.getDescs())) {
sourceBuilder.sort(query.getDescs(), SortOrder.DESC);
}
sourceBuilder.query(queryBuilder);
log.info("查询返回条件:" + sourceBuilder.toString());
searchRequest.source(sourceBuilder);
try {
return client.search(searchRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
log.warn("条件查询索引{}时出错", index);
log.warn("条件查询索引时出错:", e);
}
return new SearchResponse();
}
public List<Map<String, Object>> getEsSumList(String index, Query query, SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchResponse searchResponse = getSearchResponse(index, query, sourceBuilder, queryBuilder);
RestStatus status = searchResponse.status();
if (status.getStatus() == 200) {
List sourceList = new ArrayList<>();
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
return sourceList;
}
return new ArrayList<>();
}
public IPage searchDataScrollListPage(String index, Query query, SearchSourceBuilder sourceBuilder, QueryBuilder queryBuilder) {
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.scroll(TimeValue.timeValueMinutes(1L));
sourceBuilder.query(queryBuilder);
sourceBuilder.size(query.getSize());
sourceBuilder.trackTotalHits(true);
if (StringUtils.isNotEmpty(query.getAscs())) {
sourceBuilder.sort(query.getAscs(), SortOrder.ASC);
}
if (StringUtils.isNotEmpty(query.getDescs())) {
sourceBuilder.sort(query.getDescs(), SortOrder.DESC);
}
log.info("查询返回条件:" + sourceBuilder.toString());
searchRequest.source(sourceBuilder);
String scrollId = null;
SearchResponse scrollResponse = null;
Scroll scroll = new Scroll(TimeValue.timeValueMinutes(2));
List<String> scrollIds = new ArrayList<>();
for (int i = 0; i < query.getCurrent(); i++) {
try {
if (i == 0) {
searchRequest.scroll(scroll);
scrollResponse = client.search(searchRequest, RequestOptions.DEFAULT);
}
else {
SearchScrollRequest searchScrollRequest = new SearchScrollRequest(scrollId);
searchScrollRequest.scroll(scroll);
scrollResponse = client.scroll(searchScrollRequest, RequestOptions.DEFAULT);
}
scrollId = scrollResponse.getScrollId();
scrollIds.add(scrollId);
} catch (Exception e) {
log.error("条件查询索引{}时出错", index);
}
}
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.scrollIds(scrollIds);
try {
client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
log.error("清除滚动查询游标id失败{}时出错:", index);
log.error("清除滚动查询游标出错:", e);
}
List sourceList = new ArrayList<>();
IPage page = Condition.getPage(query);
if (!Func.isEmpty(scrollResponse)) {
SearchHits hits = scrollResponse.getHits();
TotalHits totalHits = scrollResponse.getHits().getTotalHits();
log.info("共查出{}条记录", totalHits);
for (SearchHit searchHit : hits) {
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap);
}
page.setRecords(sourceList);
page.setTotal(totalHits.value);
}
return page;
}
}
组装BoolQueryBuilder,Map必须包含三个字段name、value、nameType
public BoolQueryBuilder queryBuilder(List<Map<String, Object>> params, GoldNetUser goldNetUser) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.termQuery("isDeleted", 0));
if(Func.isEmpty(params)){
return queryBuilder;
}
for (Map<String, Object> data : params) {
if (Func.isEmpty(data.get("name")) || Func.isEmpty(data.get("value")) || Func.isEmpty(data.get("nameType"))) {
continue;
}
String type = data.get("nameType").toString();
String fieldName = data.get("name").toString();
Object value = data.get("value");
if (type.equals(SearchTypeEnum.EXACTMATCH.getFieldName())) {
if(value instanceof String){
queryBuilder.must(QueryBuilders.termsQuery(fieldName + ".keyword", value));
}else{
queryBuilder.must(QueryBuilders.termsQuery(fieldName, value));
}
} else if (type.equals(SearchTypeEnum.LIKEMATCH.getFieldName())) {
queryBuilder.must(QueryBuilders.wildcardQuery(fieldName + ".keyword", ("*" + value + "*")));
} else if (type.equals(SearchTypeEnum.DATE.getFieldName())) {
String[] dates = value.toString().split(",");
long startDate = Func.isEmpty(dates[0]) ? 0 : Long.parseLong(dates[0]);
long endDate = Func.isEmpty(dates[1]) ? 0 : Long.parseLong(dates[1]);
if (startDate > 0 && endDate > 0) {
queryBuilder.must(QueryBuilders.rangeQuery(fieldName + "TimeStamp").gte(startDate).lte(endDate));
}
} else if (type.equals(SearchTypeEnum.ARRAYMATCH.getFieldName())) {
queryBuilder.must(QueryBuilders.termsQuery(fieldName + ".keyword", (List<String>) value));
}
}
return queryBuilder;
}
nameType的枚举类
public enum SearchTypeEnum {
LIKEMATCH(10, "like", "模糊匹配"),
EXACTMATCH(20, "exact", "精确匹配"),
DATE(30, "date", "日期范围匹配"),
GT(40, "gt", "大于"),
LT(50, "lt", "小于"),
ARRAYMATCH(60, "array", "数组格式"),
SCAN(70, "scan", "发票影像件-特殊");
private final Integer code;
private final String fieldName;
private final String fieldDesc;
private static Map map = new HashMap();
private SearchTypeEnum(Integer code, String fieldName, String fieldDesc) {
this.code = code;
this.fieldName = fieldName;
this.fieldDesc = fieldDesc;
}
public Integer getCode() {
return this.code;
}
public String getFieldName() {
return this.fieldName;
}
public String getFieldDesc() {
return this.fieldDesc;
}
public static SearchTypeEnum valueOf(int code) {
return (SearchTypeEnum)map.get(code);
}
static {
SearchTypeEnum[] var0 = values();
int var1 = var0.length;
for(int var2 = 0; var2 < var1; ++var2) {
SearchTypeEnum searchTypeEnum = var0[var2];
map.put(searchTypeEnum.code, searchTypeEnum);
}
}
}
综合应用
public R objections(CommonQueryParam param, Query query) {
User user = AuthUtil.getUser();
BoolQueryBuilder queryBuilder = commonService.queryBuilder(param.getParam(), user);
queryBuilder.must(QueryBuilders.termQuery("enterpriseId.keyword", user.getEnterpriseId()));
queryBuilder.mustNot(QueryBuilders.termQuery("arrivalStatus.keyword", "0"));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.trackTotalHits(true);
Ipage page = esUtil.searchDataPage(ES_REC_SHIPMENT_ORDER_INDEX, query, sourceBuilder, queryBuilder);
return R.data(page);
}