Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,58 @@
"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": [
"redis/search/query-operators/overview",
{
"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
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>
106 changes: 106 additions & 0 deletions redis/search/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: Getting Started
---

This section demonstrates a complete workflow: creating an index, adding data, and searching.

<Tabs>

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

const redis = Redis.fromEnv();

// Create an index for product data stored as JSON
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("F64"),
inStock: s.boolean(),
}),
});

// Add some products (standard Redis JSON commands)
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,
});

await redis.json.set("product:3", "$", {
name: "Coffee Maker",
description: "Programmable coffee maker with built-in grinder",
category: "kitchen",
price: 89.99,
inStock: false,
});

// Wait for indexing to complete (optional, for immediate queries)
await index.waitIndexing();

// Search for products
const wirelessProducts = await index.query({
filter: { description: "wireless" },
});

for (const product of wirelessProducts) {
console.log(product);
}

// Search with more filters
const runningProducts = await index.query({
filter: { description: "running", inStock: true },
});

for (const product of runningProducts) {
console.log(product);
}

// Count matching documents
const count = await index.count({ filter: { price: { $lt: 150 } } });
console.log(count);
```
</Tab>

<Tab title="Redis CLI">
```bash
# Create an index for product data stored as JSON
SEARCH.CREATE products ON JSON PREFIX 1 product: SCHEMA name TEXT description TEXT category TEXT NOTOKENIZE price F64 FAST inStock BOOL

# Add some products (standard Redis JSON commands)
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}'
JSON.SET product:3 $ '{"name": "Coffee Maker", "description": "Programmable coffee maker with built-in grinder", "category": "kitchen", "price": 89.99, "inStock": false}'

# Wait for indexing to complete (optional, for immediate queries)
SEARCH.WAITINDEXING products

# Search for products
SEARCH.QUERY products '{"description": "wireless"}'

# Search with more filters
SEARCH.QUERY products '{"description": "running", "inStock": true}'

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

</Tabs>
Loading