Fix elastic dataset consistency (impacts memory)

This commit is contained in:
George Kalampokis 2021-08-24 17:05:28 +03:00
parent c964af25b5
commit bfbc271b56
1 changed files with 6 additions and 6 deletions

View File

@ -131,7 +131,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
criteria.getSortCriteria().forEach(sortCriteria -> {
switch(sortCriteria.getColumnType()) {
case COLUMN:
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
break;
case JOIN_COLUMN:
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
@ -145,10 +145,10 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.tags"}, null)));
searchSourceBuilder.query(nestedQueryBuilder).from(criteria.getOffset()).fetchSource("datasets.tags", null);
if (criteria.getSize() > 0) {
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset())*/.fetchSource("datasets.tags", null);
/*if (criteria.getSize() > 0) {
searchSourceBuilder.size(criteria.getSize());
}
}*/
sortBuilders.forEach(searchSourceBuilder::sort);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
@ -191,7 +191,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
criteria.getSortCriteria().forEach(sortCriteria -> {
switch(sortCriteria.getColumnType()) {
case COLUMN:
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
break;
case JOIN_COLUMN:
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
@ -205,7 +205,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)));
searchSourceBuilder.query(nestedQueryBuilder).from(criteria.getOffset()).size(criteria.getSize()).fetchSource("datasets.id", null);
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
sortBuilders.forEach(searchSourceBuilder::sort);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);