Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
igorkharchenko opened this issue Nov 14, 2023 · 0 comments

Comments

@igorkharchenko
Copy link

igorkharchenko commented Nov 14, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant