# 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="Python">
```python
from upstash_redis import Redis

redis = Redis.from_env()

index = redis.search.create_index(
    name="products",
    data_type="json",
    prefixes="product:",
    schema={
        "name": "TEXT",
        "description": "TEXT",
        "category": {"type": "TEXT", "notokenize": True},
        "price": "F64",
        "inStock": "BOOL",
    },
)
```
</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>

<Note>
Create an index once, not on every request. `createIndex` throws if an index with
the same name already exists. To make setup safely re-runnable, pass `exists_ok=True`
in the Python SDK, or wrap the call in a `try/catch` in TypeScript.
</Note>

## 2. Add Data

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

<Note>
Writes are indexed asynchronously: a `JSON.SET` returns before the document is
searchable. For demos and tests, call `waitIndexing()` / `wait_indexing()` to
block until pending updates are applied. In production, queries running on a later
request will normally hit an up-to-date index without waiting.
</Note>

<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,
});

await index.waitIndexing();
```
</Tab>

<Tab title="Python">
```python
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,
})

redis.json.set("product:2", "$", {
    "name": "Running Shoes",
    "description": "Lightweight running shoes with advanced cushioning technology",
    "category": "sports",
    "price": 129.99,
    "inStock": True,
})

index.wait_indexing()
```
</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="Python">
```python
results = index.query(filter={"description": "wireless"})

count = 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>

## Next Steps

<CardGroup cols={2}>
  <Card
    title="Schema Definition"
    icon="table-columns"
    href="/redis/search/schema-definition"
  >
    Define the fields you want to index and how they are matched
  </Card>
  <Card
    title="Querying"
    icon="magnifying-glass"
    href="/redis/search/querying"
  >
    Learn the JSON-based query language with filters and operators
  </Card>
  <Card
    title="Aggregations"
    icon="layer-group"
    href="/redis/search/aggregations"
  >
    Group and summarize your indexed data with aggregation pipelines
  </Card>
  <Card
    title="Recipes"
    icon="book-open"
    href="/redis/search/recipes/overview"
  >
    Complete, real-world examples you can adapt to your own use cases
  </Card>
</CardGroup>
