Closed lem0na closed 6 months ago
Hey @lem0na, thank for the detailed issue :)
After checking with RediSearch team,
FILTER
or any operation in the pipeline after a GROUPBY
can only relate to fields which the GROUPBY
will define AS
If you relate to other fields you will get an error that the Property is not loaded or not in the pipeline.
FILTER
before the GROUPBY
can relate to any available Property
As you said, I arranged the query so that it is in the order that appears in documentation of FT.AGGREGATE, there the FILTER
comes after GROUPBY
.
Try to add the @StatusId to the GROUPBY
and tell me if you got the result you expected to get. you can do it like this:
var request = new AggregationRequest("*", 3)
.Filter("@StatusId==1")
.GroupBy(
new List<string> { "@CreatedDay", "@StatusId" },
new List<Reducer>
{
Reducers.CountDistinct("@UserId"),
Reducers.Count().As("count")
}
);
Beyond that, A little thing I noticed is this line:
SearchCommandBuilder.DropIndex("idx:users", dd: true);
Builds the command and returns it to you, but not sending the command to Redis, if you want to sent it to redis you need to do like this:
ISearchCommands ft = db.FT();
ft.DropIndex("idx:users", dd: true);
In any case, don'd do it at the start, because if you send the command when Redis does not know the index yet, you will get an error.
Hi @shacharPash Thanks for the quick response. I am a newbie using Redis outside the KV store - a few days ago, I discovered that Redis now supports a lot of features that I had thought of. The code that you provided returns the expected results. But I am wondering why TotalResults is 5, not 2 as this is the real number of results. When I execute it in CLI it also returns 5 which is probably related to Redis and not to the library. Why I am asking - as far as I understood I have two options to get the data:
About
SearchCommandBuilder.DropIndex("idx:users", dd: true);
it is leftover from some previous tests. Thanks for mentioning it.
Hi @lem0na, after researching the topic and reading the documentation, it turns out that the order of the arguments within the FT.AGGREGATE command has meaning, and also that you can send more than one argument. Currently NRedisStack does not allow these two things and I will fix it. Thanks for bringing it to my attention.
Thanks for reporting an issue in NRedisStack! Please update the appropriate text below, as much data as possible really helps!
NRedisStack Version: 0.11.0
Redis Stack Version: redis_version:7.2.3 from official docker image MODULE LIST name timeseries ver 11009 path /opt/redis-stack/lib/redistimeseries.so args name redisgears_2 ver 20014 path /opt/redis-stack/lib/redisgears.so args v8-plugin-path /opt/redis-stack/lib/libredisgears_v8_plugin.so name search ver 20809 path /opt/redis-stack/lib/redisearch.so args MAXSEARCHRESULTS 10000 MAXAGGREGATERESULTS 10000 name bf ver 20608 path /opt/redis-stack/lib/redisbloom.so args name RedisCompat ver 1 path /opt/redis-stack/lib/rediscompat.so args name ReJSON ver 20607 path /opt/redis-stack/lib/rejson.so args
Description: I am trying to evaluate Redis for aggregations. I saved a few JSON records and tried to aggregate using filter on one of the properties. The generated query throws an exception that a property is not loaded or in the pipeline.
example code
I expect the generated query to be
which executed in the CLI returns expected results. But the actual query is
which executed in the CLI throws an error "Property
StatusId
not loaded nor in pipeline".In AggregationRequest class I see that there is a function SerializeRedisArgs which looks like generates the query with a specific order of commands which probably is the issue.
I am doing something wrong or this is a bug?