1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Fixed search example for JSON.

This commit is contained in:
Simon Prickett
2021-11-24 20:40:17 +00:00
parent 7d58f05479
commit 862b9a132e

View File

@@ -14,8 +14,14 @@ async function searchJSON() {
type: SchemaFieldTypes.TEXT, type: SchemaFieldTypes.TEXT,
SORTABLE: 'UNF' SORTABLE: 'UNF'
}, },
'$.age': SchemaFieldTypes.NUMERIC, '$.age': {
'$.coins': SchemaFieldTypes.NUMERIC type: SchemaFieldTypes.NUMERIC,
AS: 'age'
},
'$.coins': {
type: SchemaFieldTypes.NUMERIC,
AS: 'coins'
}
}, { }, {
ON: 'JSON', ON: 'JSON',
PREFIX: 'noderedis:users' PREFIX: 'noderedis:users'
@@ -45,14 +51,14 @@ async function searchJSON() {
]); ]);
// Search all users under 30 // Search all users under 30
// https://oss.redis.com/redisearch/Commands/#ftsearch console.log('Users under 30 years old:');
// TODO: why "$.age:[-inf, 30]" does not work?
console.log( console.log(
await client.ft.search('idx:users', '*') // https://oss.redis.com/redisearch/Commands/#ftsearch
await client.ft.search('idx:users', '@age:[0 30]')
); );
// { // {
// total: 1, // total: 1,
// documents: [...] // documents: [ { id: 'noderedis:users:2', value: [Object] } ]
// } // }
// Some aggregrations, what's the average age and total number of coins... // Some aggregrations, what's the average age and total number of coins...
@@ -63,11 +69,11 @@ async function searchJSON() {
type: AggregateSteps.GROUPBY, type: AggregateSteps.GROUPBY,
REDUCE: [{ REDUCE: [{
type: AggregateGroupByReducers.AVG, type: AggregateGroupByReducers.AVG,
property: '$.age', property: 'age',
AS: 'averageAge' AS: 'averageAge'
}, { }, {
type: AggregateGroupByReducers.SUM, type: AggregateGroupByReducers.SUM,
property: '$.coins', property: 'coins',
AS: 'totalCoins' AS: 'totalCoins'
}] }]
}] }]