FT.AGGREGATE index 'red' GROUPBY 1 @category REDUCE count 0 AS 'hits'
1) (integer) 1
2)1) "category"
2) "212,215,221"
3) "hits"
4) "1"
I was expecting 3 results.
It seems FT.aggregate does not really work on tags field with multiple entries?
It is not splitting them in multiple fields.
As there is no other way to have multiple entries, having this working correctly would be great for people using facets... like me :)
@lumina7 can you please add a full example including some example docs?
ok, here is the whole step to reproduce.
Basically create an index with a text field and a tag field.
FT.CREATE myidx SCHEMA productname TEXT category TAG SORTABLE
Now add some documents to the index with a multiple tags (to add multiple tags, the default separator is the comma)
FT.ADD myidx p1 1.0 NOSAVE FIELDS productname 'red flower' category 200,201,202
FT.ADD myidx p2 1.0 NOSAVE FIELDS productname 'red lily' category 200
FT.ADD myidx p3 1.0 NOSAVE FIELDS productname 'red rose' category 201
Now lets do the aggregate to get the facets for the search 'red'
Expected results:
2 hits for category 200
2 hits for category 201
1 hit for category 202
redis > FT.AGGREGATE myidx 'red' GROUPBY 1 @category REDUCE count 0 AS 'hits'
1) (integer) 3
2) 1) "category"
2) "201"
3) "hits"
4) "1"
3) 1) "category"
2) "200,201,202"
3) "hits"
4) "1"
4) 1) "category"
2) "200"
3) "hits"
4) "1"
So the results we got is :
1 hit for category 201 (instead of 2)
1 hit for category 200,201,202 (that one do not exist, that's three categories)
1 hit for category 200 (instead of 2)
FT.AGGREGATE do not work with TAGS field. It consider a tag field with multiple tags as a whole only (look at 200,201,202), not as different 'value', which is a problem for faceted search on multiples entries.
If I remove the multiple entries, then everything is working fine; but that's not the point.
You need to apply a split function before the Groupby https://oss.redislabs.com/redisearch/Aggregations/#list_of_string_apply_functions
Ok, I see it now in the doc but it is really not well documented.
Can someone show me how to do that???
127.0.0.1:6379> FT.CREATE idx SCHEMA t TAG
OK
127.0.0.1:6379> FT.ADD idx doc1 1.0 FIELDS t foo,bar
OK
127.0.0.1:6379> FT.ADD idx doc2 1.0 FIELDS t foo,bar,koo
OK
127.0.0.1:6379> FT.ADD idx doc 1.0 FIELDS t foo
OK
127.0.0.1:6379> FT.AGGREGATE idx * LOAD 1 @t APPLY "split(@t)" as t1 GROUPBY 1 @t1 REDUCE count 0 AS 'hits'
1) (integer) 3
2) 1) "t1"
2) "foo"
3) "hits"
4) "3"
3) 1) "t1"
2) "bar"
3) "hits"
4) "2"
4) 1) "t1"
2) "koo"
3) "hits"
4) "1"
I found it by myself by trial and error, thank you for the help!!!!
FT.AGGREGATE myidx 'red' APPLY 'split(@category,",")' as category GROUPBY 1 @category REDUCE count 0 AS 'hits'