@@ -14,8 +14,14 @@ async function searchJSON() {
1414 type : SchemaFieldTypes . TEXT ,
1515 SORTABLE : 'UNF'
1616 } ,
17- '$.age' : SchemaFieldTypes . NUMERIC ,
18- '$.coins' : SchemaFieldTypes . NUMERIC
17+ '$.age' : {
18+ type : SchemaFieldTypes . NUMERIC ,
19+ AS : 'age'
20+ } ,
21+ '$.coins' : {
22+ type : SchemaFieldTypes . NUMERIC ,
23+ AS : 'coins'
24+ }
1925 } , {
2026 ON : 'JSON' ,
2127 PREFIX : 'noderedis:users'
@@ -45,14 +51,14 @@ async function searchJSON() {
4551 ] ) ;
4652
4753 // Search all users under 30
48- // https://oss.redis.com/redisearch/Commands/#ftsearch
49- // TODO: why "$.age:[-inf, 30]" does not work?
54+ console . log ( 'Users under 30 years old:' ) ;
5055 console . log (
51- await client . ft . search ( 'idx:users' , '*' )
56+ // https://oss.redis.com/redisearch/Commands/#ftsearch
57+ await client . ft . search ( 'idx:users' , '@age:[0 30]' )
5258 ) ;
5359 // {
5460 // total: 1,
55- // documents: [... ]
61+ // documents: [ { id: 'noderedis:users:2', value: [Object] } ]
5662 // }
5763
5864 // Some aggregrations, what's the average age and total number of coins...
@@ -63,11 +69,11 @@ async function searchJSON() {
6369 type : AggregateSteps . GROUPBY ,
6470 REDUCE : [ {
6571 type : AggregateGroupByReducers . AVG ,
66- property : '$. age' ,
72+ property : 'age' ,
6773 AS : 'averageAge'
6874 } , {
6975 type : AggregateGroupByReducers . SUM ,
70- property : '$. coins' ,
76+ property : 'coins' ,
7177 AS : 'totalCoins'
7278 } ]
7379 } ]
0 commit comments