|
@@ -17,7 +17,6 @@ import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
|
|
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
|
|
|
import co.elastic.clients.elasticsearch.core.search.TotalHits;
|
|
import co.elastic.clients.elasticsearch.core.search.TotalHits;
|
|
|
import co.elastic.clients.elasticsearch.core.search.TotalHitsRelation;
|
|
import co.elastic.clients.elasticsearch.core.search.TotalHitsRelation;
|
|
|
-import co.elastic.clients.json.JsonData;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -99,26 +98,13 @@ public class SearchService {
|
|
|
*/
|
|
*/
|
|
|
public List<NginxLog> searchByPage(String indexName, int pageSize, int pageNumber,
|
|
public List<NginxLog> searchByPage(String indexName, int pageSize, int pageNumber,
|
|
|
Query query, String sortField, SortOrder sortOrder) throws IOException {
|
|
Query query, String sortField, SortOrder sortOrder) throws IOException {
|
|
|
- //String sortField = "requestTimestamp";
|
|
|
|
|
- //Query query = RangeQuery.of(r -> r.field("age").gte(JsonData.of(8)))._toQuery();
|
|
|
|
|
- Query query11 = EsQuery.getOrQuery();
|
|
|
|
|
- Query query1 = EsQuery.getAndQuery();
|
|
|
|
|
- // 等值查询
|
|
|
|
|
- //Query termQuery = EsQuery.getTermQuery(fieldName, fieldValue);
|
|
|
|
|
- //Query rangeQuery = EsQuery.getRangeQuery(fieldName);
|
|
|
|
|
- String dateField = "timeIso8601";
|
|
|
|
|
- String dateValue = "2023-11-08";
|
|
|
|
|
- String start0 = String.format("%sT00:00:00", dateValue);
|
|
|
|
|
- String end0 = String.format("%sT23:59:59", dateValue);
|
|
|
|
|
-
|
|
|
|
|
int start = (pageNumber-1)*pageSize;
|
|
int start = (pageNumber-1)*pageSize;
|
|
|
SearchRequest searchRequest = SearchRequest.of(s -> s
|
|
SearchRequest searchRequest = SearchRequest.of(s -> s
|
|
|
.index(indexName)
|
|
.index(indexName)
|
|
|
- .query(q -> q.range(r -> r.field(dateField).gte(JsonData.of(start0)).lte(JsonData.of(end0))))
|
|
|
|
|
.query(query)
|
|
.query(query)
|
|
|
.from(start)
|
|
.from(start)
|
|
|
.size(pageSize)
|
|
.size(pageSize)
|
|
|
- // 按 id 字段降序排列
|
|
|
|
|
|
|
+ // 按指定字段升序或降序排列
|
|
|
.sort(f -> f.field(o -> o.field(sortField).order(sortOrder)))
|
|
.sort(f -> f.field(o -> o.field(sortField).order(sortOrder)))
|
|
|
);
|
|
);
|
|
|
|
|
|