> ## Documentation index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Ask it with GET https://upstash.com/docs/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.
> Feature requests: https://upstash.com/docs/common/help/feature-requests.md lists what users asked for and how to vote for a request or add one.
> Page rating: `GET https://upstash.com/docs/feedback?path=/docs/redis/search/counting&helpful=true` (or `false`) records whether this page helped. An optional `comment` (URL-encoded, at most 500 characters) says what was missing or wrong. It is anonymous and needs no key. Comments hold no code, secrets or personal data.

# Counting

The [`SEARCH.COUNT`](/redis/commands/search/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="Python">
```python
# Count all electronics
products.count(filter={"category": "electronics"})

# Count in-stock items under $100
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>
