Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@igorkharchenko

Description

@igorkharchenko

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions