lettucemod icon indicating copy to clipboard operation
lettucemod copied to clipboard

ftAggregate ignores limit in options, or maybe i'm missing something

Open igorkharchenko opened this issue 1 year ago • 0 comments

Hello, I am trying to retrieve results with FT.AGGREGATE and I want to fetch all results with one query.
The task is, given one GPS point, sort all items (~1500) by distance around this point (coordinates of all items in index are different).
The problem is when I set limit in options to 1000000, I always get only 10 results instead of all.

The code is:

        RediSearchAsyncCommands<String, String> rediSearchCommands = connection.async();

        // RedisItem fields: String guid, Point coordinates
        String indexName = RedisItem.class.getName() + "Idx";
        String query = queryBuilder.build();

        String longitude = "37.642042";
        String latitude = "55.820642";

        AggregateOptions.Builder<String, String> options = AggregateOptions.builder();
        options.loads("guid", "coordinates");
        String groupId = MessageFormat.format("geodistance(@coordinates, \"{0},{1}\")", longitude, latitude);
        options.operation(AggregateOperation
                .apply(groupId)
                .as("distance"));
        options.operation(AggregateOperation
                .sort(Sort.Property.asc("distance"))
                .build());
        options.limit(0, 1000000);

        String query = "(@coordinates:[40.790325734421394 42.71154290577113 8806301.180545114 m])";

        rediSearchCommands
                .ftAggregate(indexName, query, options.build())
                .thenAcceptAsync((List<Map<String, Object>> results) -> {
                    Logger.logInfo("results amount = " + results.size());
                });

In Redis-stack monitor this native query is being generated:

"FT.AGGREGATE" "com.some_company.entities.RedisItemIdx" "(@coordinates:[40.790325734421394 42.71154290577113 8806301.180545114 m]) " "LOAD" "2" "guid" "coordinates" "APPLY" "geodistance(@coordinates, \"37.642042,55.820642\")" "AS" "distance" "SORTBY" "2" "@distance" "ASC"

The question is why LIMIT isn't set in native query? What I'm doing wrong?(
Maybe I need to use cursors or something?

igorkharchenko avatar Nov 14 '23 06:11 igorkharchenko