I have written java code in Spring boot using elasticsearch-rest-high-level-client
7.17.4
now I want to migrate to elastic-search 8
how I can write term query
SearchRequest searchRequest = new SearchRequest(ZEEBE_JOB);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (taskkey != null) {
BoolQueryBuilder filter = boolQueryBuilder.filter(QueryBuilders.termQuery("key", taskkey));
log.info("task query: {}", filter);
// boolQueryBuilder.filter(QueryBuilders.termQuery("intent", "CREATED"));
}
if (processInstanceKey != null) {
BoolQueryBuilder filter = boolQueryBuilder.filter(QueryBuilders.termQuery("value.processInstanceKey", processInstanceKey));
log.info("process instance: {}", filter);
}
if (assignee != null) {
BoolQueryBuilder filter = boolQueryBuilder.filter(QueryBuilders.termQuery("value.customHeaders.io.camunda.zeebe:assignee", assignee));
log.info("assignee: {}", filter);
}
if (start != null && end != null) {
long startMillis = start.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
log.info("startMillis : {}", startMillis);
long endMillis = end.atStartOfDay().plusDays(1).minusSeconds(1).toInstant(ZoneOffset.UTC).toEpochMilli();
log.info("endMillis : {}", endMillis);
BoolQueryBuilder filter = boolQueryBuilder.filter(QueryBuilders.rangeQuery("timestamp").gte(start).lte(end).format("yyyy-MM-dd"));
log.info("time filter : {}", filter);
}
if (intent != null) {
BoolQueryBuilder filter = boolQueryBuilder.filter(QueryBuilders.termQuery("intent", intent));
log.info("intent : {}", filter);
}
searchSourceBuilder.query(boolQueryBuilder);
searchSourceBuilder.from(from);
searchRequest.source(searchSourceBuilder);
List<TaskDto> taskList = new ArrayList<>();
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] hits = searchResponse.getHits().getHits();
long totalRecords = searchResponse.getHits().getTotalHits().value;
searchSourceBuilder.sort("timestamp", SortOrder.DESC);
int recordFrom = searchSourceBuilder.from();
int size1 = searchSourceBuilder.size();