FtAggregate always returning only 10 rows while sorting

Skip to first unread message

Deepak Singhal

Jan 9, 2024, 7:45:12 AMJan 9
to Redis DB
Expected Behavior

Performing sort by aggregation using .ftAggregate should return all the results and cursor as per the provided count.

Actual Behavior

I am trying to run Aggregation on my Redis Stack server using UnifiedJedis Bean. When I execute the command using .ftAggregate it returns me only 10 rows with cursor 0, which means end of results where as my server contains ~7000 JSON objects stored in it.

Steps to reproduce:
  1. Created UnifiedJedis bean and autowired in my service,
  2. Build Aggregation Builder and pass it to .ftAggregate method of unifiedJedis
  3. In Aggregation Builder passed fields that needs to be sorted by and applied cursor count as 1000
  4. Kept MAX_IDLE_TIME as 3000
@Bean public UnifiedJedis unifiedJedis(JedisConnectionFactory jedisConnectionFactory) { HostAndPort hostAndPort = new HostAndPort( jedisConnectionFactory.getHostName(), jedisConnectionFactory.getPort()); return new UnifiedJedis(hostAndPort); }

Implementation in my service

AggregationBuilder aggregationBuilder = createAggregationBuilder(request, chunkSize); AggregationResult result = unifiedJedis.ftAggregate(indexName, aggregationBuilder); LOGGER.info("result 1 size :: " + result.getRows().size()); LOGGER.info("Cursor returned 1:: " + result.getCursorId());

//Response of above Logs
result 1 size :: 10
Cursor returned 1:: 0

// my method for creating the Aggregation Builder, chunkSize passed as 1000

public AggregationBuilder createAggregationBuilder(BaseRequest request, int chunkSize) { SortedField[] sortedFields = prepareSortFields(request); return new AggregationBuilder("*") .loadAll() .sortBy(sortedFields) .cursor(chunkSize, MAX_IDLE_TIME); } private SortedField[] prepareSortFields(BaseRequest request) { List<SortedField> sortedFieldList = new ArrayList<>(); if(!request.getOrderByFields().isEmpty()) { request.getOrderByFields().forEach(sort -> { SortedField.SortOrder order = sort.getSortBy().equalsIgnoreCase("asc") ? SortedField.SortOrder.ASC : SortedField.SortOrder.DESC; SortedField sortedField = new SortedField("@" + sort.getFieldName(), order); sortedFieldList.add(sortedField); }); } return sortedFieldList.toArray(new SortedField[sortedFieldList.size()]); }
Redis / Jedis Configuration
Jedis version: 4.4.6
Redis version: 7.2.3
Java version: 17
redis-om-spring version: 0.8.7

I am using an older version of Jedis library, since redis-om-spring is not compatible to work with latest version of it.

Can you please check and let me know why this query is not working properly, same query is returning only 10 rows on RedisInsight as well.

Query prepared by above code:

"FT.AGGREGATE" "myIndex" "*" "LOAD" "*" "SORTBY" "4" "@state" "ASC" "@empId" "DESC" "WITHCURSOR" "COUNT" "1000" "MAXIDLE" "3000"

Reply all
Reply to author
0 new messages