From 862b9a132e3e35d7b5bc3411909cec1e5804943d Mon Sep 17 00:00:00 2001 From: Simon Prickett Date: Wed, 24 Nov 2021 20:40:17 +0000 Subject: [PATCH] Fixed search example for JSON. --- examples/search-json.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/search-json.js b/examples/search-json.js index c44bf7eef6..a608d3aefa 100644 --- a/examples/search-json.js +++ b/examples/search-json.js @@ -14,8 +14,14 @@ async function searchJSON() { type: SchemaFieldTypes.TEXT, SORTABLE: 'UNF' }, - '$.age': SchemaFieldTypes.NUMERIC, - '$.coins': SchemaFieldTypes.NUMERIC + '$.age': { + type: SchemaFieldTypes.NUMERIC, + AS: 'age' + }, + '$.coins': { + type: SchemaFieldTypes.NUMERIC, + AS: 'coins' + } }, { ON: 'JSON', PREFIX: 'noderedis:users' @@ -45,14 +51,14 @@ async function searchJSON() { ]); // Search all users under 30 - // https://oss.redis.com/redisearch/Commands/#ftsearch - // TODO: why "$.age:[-inf, 30]" does not work? + console.log('Users under 30 years old:'); 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, - // documents: [...] + // documents: [ { id: 'noderedis:users:2', value: [Object] } ] // } // Some aggregrations, what's the average age and total number of coins... @@ -63,11 +69,11 @@ async function searchJSON() { type: AggregateSteps.GROUPBY, REDUCE: [{ type: AggregateGroupByReducers.AVG, - property: '$.age', + property: 'age', AS: 'averageAge' }, { type: AggregateGroupByReducers.SUM, - property: '$.coins', + property: 'coins', AS: 'totalCoins' }] }]