Gathering detailed insights and metrics for @valkey/search
Gathering detailed insights and metrics for @valkey/search
Gathering detailed insights and metrics for @valkey/search
Gathering detailed insights and metrics for @valkey/search
npm install @valkey/search
Typescript
Module System
Node Version
NPM Version
78.8
Supply Chain
100
Quality
78.9
Maintenance
100
Vulnerability
100
License
TypeScript (99.33%)
JavaScript (0.66%)
Dockerfile (0.01%)
Total Downloads
69,994
Last Day
4
Last Week
1,214
Last Month
5,404
Last Year
69,815
MIT License
7 Stars
1,950 Commits
2 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Feb 19, 2025
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
@valkey/search@1.0.0
Unpacked Size
75.48 kB
Size
15.61 kB
File Count
74
NPM Version
10.5.0
Node Version
21.7.1
Published on
Apr 01, 2024
Cumulative downloads
Total Downloads
Last Day
-78.9%
4
Compared to previous day
Last Week
-3.7%
1,214
Compared to previous week
Last Month
-3.8%
5,404
Compared to previous month
Last Year
38,902.8%
69,815
Compared to previous year
1
This package provides support for the RediSearch module, which adds indexing and querying support for data stored in Redis Hashes or as JSON documents with the RedisJSON module. It extends the Node Redis client to include functions for each of the RediSearch commands.
To use these extra commands, your Redis server must have the RediSearch module installed. To index and query JSON documents, you'll also need to add the RedisJSON module.
For complete examples, see search-hashes.js
and search-json.js
in the Node Redis examples folder.
Before we can perform any searches, we need to tell RediSearch how to index our data, and which Redis keys to find that data in. The FT.CREATE command creates a RediSearch index. Here's how to use it to create an index we'll call idx:animals
where we want to index hashes containing name
, species
and age
fields, and whose key names in Redis begin with the prefix noderedis:animals
:
1await client.ft.create( 2 "idx:animals", 3 { 4 name: { 5 type: SchemaFieldTypes.TEXT, 6 SORTABLE: true, 7 }, 8 species: SchemaFieldTypes.TAG, 9 age: SchemaFieldTypes.NUMERIC, 10 }, 11 { 12 ON: "HASH", 13 PREFIX: "noderedis:animals", 14 } 15);
See the FT.CREATE
documentation for information about the different field types and additional options.
Once we've created an index, and added some data to Redis hashes whose keys begin with the prefix noderedis:animals
, we can start writing some search queries. RediSearch supports a rich query syntax for full-text search, faceted search, aggregation and more. Check out the FT.SEARCH
documentation and the query syntax reference for more information.
Let's write a query to find all the animals where the species
field has the value dog
:
1const results = await client.ft.search("idx:animals", "@species:{dog}");
results
looks like this:
1{ 2 total: 2, 3 documents: [ 4 { 5 id: 'noderedis:animals:4', 6 value: { 7 name: 'Fido', 8 species: 'dog', 9 age: '7' 10 } 11 }, 12 { 13 id: 'noderedis:animals:3', 14 value: { 15 name: 'Rover', 16 species: 'dog', 17 age: '9' 18 } 19 } 20 ] 21}
RediSearch can also index and query JSON documents stored in Redis using the RedisJSON module. The approach is similar to that for indexing and searching data in hashes, but we can now use JSON Path like syntax and the data no longer has to be flat name/value pairs - it can contain nested objects and arrays.
As before, we create an index with the FT.CREATE
command, this time specifying we want to index JSON documents that look like this:
1{ 2 name: 'Alice', 3 age: 32, 4 coins: 100 5}
Each document represents a user in some system, and users have name, age and coins properties.
One way we might choose to index these documents is as follows:
1await client.ft.create( 2 "idx:users", 3 { 4 "$.name": { 5 type: SchemaFieldTypes.TEXT, 6 SORTABLE: "UNF", 7 }, 8 "$.age": { 9 type: SchemaFieldTypes.NUMERIC, 10 AS: "age", 11 }, 12 "$.coins": { 13 type: SchemaFieldTypes.NUMERIC, 14 AS: "coins", 15 }, 16 }, 17 { 18 ON: "JSON", 19 PREFIX: "noderedis:users", 20 } 21);
Note that we're using JSON Path to specify where the fields to index are in our JSON documents, and the AS
clause to define a name/alias for each field. We'll use these when writing queries.
Now we have an index and some data stored as JSON documents in Redis (see the JSON package documentation for examples of how to store JSON), we can write some queries...
We'll use the RediSearch query language and FT.SEARCH
command. Here's a query to find users under the age of 30:
1await client.ft.search("idx:users", "@age:[0 30]");
No vulnerabilities found.
No security vulnerabilities found.