@@ -14,8 +14,14 @@ async function searchJSON() {
14
14
type : SchemaFieldTypes . TEXT ,
15
15
SORTABLE : 'UNF'
16
16
} ,
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
+ }
19
25
} , {
20
26
ON : 'JSON' ,
21
27
PREFIX : 'noderedis:users'
@@ -45,14 +51,14 @@ async function searchJSON() {
45
51
] ) ;
46
52
47
53
// 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:' ) ;
50
55
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]' )
52
58
) ;
53
59
// {
54
60
// total: 1,
55
- // documents: [... ]
61
+ // documents: [ { id: 'noderedis:users:2', value: [Object] } ]
56
62
// }
57
63
58
64
// Some aggregrations, what's the average age and total number of coins...
@@ -63,11 +69,11 @@ async function searchJSON() {
63
69
type : AggregateSteps . GROUPBY ,
64
70
REDUCE : [ {
65
71
type : AggregateGroupByReducers . AVG ,
66
- property : '$. age' ,
72
+ property : 'age' ,
67
73
AS : 'averageAge'
68
74
} , {
69
75
type : AggregateGroupByReducers . SUM ,
70
- property : '$. coins' ,
76
+ property : 'coins' ,
71
77
AS : 'totalCoins'
72
78
} ]
73
79
} ]
0 commit comments