Skip to content
Open
51 changes: 51 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,57 @@
"redis/help/managing-healthcare-data"
]
},
{
"group": "Search",
"pages": [
"redis/search/introduction",
"redis/search/getting-started",
"redis/search/index-management",
"redis/search/schema-definition",
"redis/search/querying",
"redis/search/counting",
{
"group": "Query Operators",
"pages": [
{
"group": "Boolean Operators",
"pages": [
"redis/search/query-operators/boolean-operators/overview",
"redis/search/query-operators/boolean-operators/must",
"redis/search/query-operators/boolean-operators/should",
"redis/search/query-operators/boolean-operators/must-not",
"redis/search/query-operators/boolean-operators/boost"
]
},
{
"group": "Field Operators",
"pages": [
"redis/search/query-operators/field-operators/overview",
"redis/search/query-operators/field-operators/smart-matching",
"redis/search/query-operators/field-operators/eq",
"redis/search/query-operators/field-operators/ne",
"redis/search/query-operators/field-operators/in",
"redis/search/query-operators/field-operators/range-operators",
"redis/search/query-operators/field-operators/phrase",
"redis/search/query-operators/field-operators/fuzzy",
"redis/search/query-operators/field-operators/regex",
"redis/search/query-operators/field-operators/contains",
"redis/search/query-operators/field-operators/boost"
]
}
]
},
{
"group": "Recipes",
"pages": [
"redis/search/recipes/overview",
"redis/search/recipes/e-commerce-search",
"redis/search/recipes/blog-search",
"redis/search/recipes/user-directory"
]
}
]
},
{
"group": "How To",
"pages": [
Expand Down
Binary file added img/redis-search/redis-search-cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions redis/search/counting.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Counting
---

The `SEARCH.COUNT` command returns the number of documents matching a query without retrieving them.

You can use `SEARCH.COUNT` for analytics, pagination UI (showing "X results found"),
or validating queries before retrieving results.

<Tabs>

<Tab title="TypeScript">
```ts
// Count all electronics
await products.count({
filter: {
category: "electronics",
},
});

// Count in-stock items under $100
await products.count({
filter: {
inStock: true,
price: { $lt: 100 },
},
});
```
</Tab>

<Tab title="Redis CLI">
```bash
# Count all electronics
SEARCH.COUNT products '{"category": "electronics"}'

# Count in-stock items under $100
SEARCH.COUNT products '{"inStock": true, "price": {"$lt": 100}}'
```
</Tab>

</Tabs>
101 changes: 101 additions & 0 deletions redis/search/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Quickstart
---

## 1. Create Index

<Tabs>

<Tab title="TypeScript">
```ts
import { Redis, s } from "@upstash/redis";

const redis = Redis.fromEnv();

const index = await redis.search.createIndex({
name: "products",
dataType: "json",
prefix: "product:",
schema: s.object({
name: s.string(),
description: s.string(),
category: s.string().noTokenize(),
price: s.number(),
inStock: s.boolean(),
}),
});
```
</Tab>

<Tab title="Redis CLI">
```bash
SEARCH.CREATE products ON JSON PREFIX 1 product: SCHEMA name TEXT description TEXT category TEXT NOTOKENIZE price F64 FAST inStock BOOL
```
</Tab>

</Tabs>

## 2. Add Data

Add data using standard Redis JSON commands. Any key matching the index prefix will be automatically indexed.

<Tabs>

<Tab title="TypeScript">
```ts
await redis.json.set("product:1", "$", {
name: "Wireless Headphones",
description:
"Premium noise-cancelling wireless headphones with 30-hour battery life",
category: "electronics",
price: 199.99,
inStock: true,
});

await redis.json.set("product:2", "$", {
name: "Running Shoes",
description: "Lightweight running shoes with advanced cushioning technology",
category: "sports",
price: 129.99,
inStock: true,
});
```
</Tab>

<Tab title="Redis CLI">
```bash
JSON.SET product:1 $ '{"name": "Wireless Headphones", "description": "Premium noise-cancelling wireless headphones with 30-hour battery life", "category": "electronics", "price": 199.99, "inStock": true}'
JSON.SET product:2 $ '{"name": "Running Shoes", "description": "Lightweight running shoes with advanced cushioning technology", "category": "sports", "price": 129.99, "inStock": true}'

SEARCH.WAITINDEXING products
```
</Tab>

</Tabs>

## 3. Search Data


<Tabs>

<Tab title="TypeScript">
```ts
const results = await index.query({
filter: { description: "wireless" },
});

const count = await index.count({
filter: { price: { $lt: 150 } },
});
```
</Tab>

<Tab title="Redis CLI">
```bash
SEARCH.QUERY products '{"description": "wireless"}'

SEARCH.COUNT products '{"price": {"$lt": 150}}'
```
</Tab>

</Tabs>
Loading