> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blnkfinance.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Faceting

> Learn how to aggregate and count values in your search results

## Overview

Faceting gives you total counts for any field in your results. It helps you build filters and understand how your data is grouped. You can:

* Count transactions per currency
* See how many transactions are in each status
* Group balances by ledger or identity
* Break transactions into date or amount ranges

***

## Quick start

Here's a basic faceting request that shows the total counts for the `status` and `currency` fields:

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -X POST "http://YOUR_BLNK_INSTANCE_URL/search/transactions" \
    -H "X-Blnk-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "*",
      "facet_by": "status,currency"
    }'
  ```

  ```json Response theme={"system"}
  {
    "facet_counts": [
      {
        "counts": [
          {
            "count": 1000,
            "highlighted": "APPLIED",
            "value": "APPLIED"
          },
          {
            "count": 1500,
            "highlighted": "INFLIGHT",
            "value": "INFLIGHT"
          }
          {
            "count": 500,
            "highlighted": "REJECTED",
            "value": "REJECTED"
          }
        ],
        "field_name": "status",
        "stats": {
          "total_values": 1
        }
      },
      {
        "counts": [
          {
            "count": 876,
            "highlighted": "GBP",
            "value": "GBP"
          },
          {
            "count": 821,
            "highlighted": "EUR",
            "value": "EUR"
          },
          {
            "count": 803,
            "highlighted": "USD",
            "value": "USD"
          }
        ],
        "field_name": "currency",
        "stats": {
          "total_values": 3
        }
      }
    ]
  ```
</CodeGroup>

| **Field**      | **Description**                              |
| :------------- | :------------------------------------------- |
| `field_name`   | The field being faceted.                     |
| `value`        | A unique value found in that field.          |
| `count`        | Number of documents that have this value.    |
| `counts`       | The full list of values and their counts.    |
| `total_values` | How many unique values exist for this field. |

***

## Combining faceting with filters

Faceting becomes more powerful when combined with filters. You can facet on one field while filtering on others to analyze specific subsets of your data.

<CodeGroup>
  ```bash USD transactions by status theme={"system"}
  curl -X POST "http://YOUR_BLNK_INSTANCE_URL/search/transactions" \
    -H "X-Blnk-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "*",
      "filter_by": "currency:=USD",
      "facet_by": "status"
    }'
  ```

  ```bash Customer balances by currency theme={"system"}
  curl -X POST "http://YOUR_BLNK_INSTANCE_URL/search/balances" \
    -H "X-Blnk-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "*",
      "filter_by": "identity_id:=idt_28f25ef6-2e0d-4fa6-891c-37fc409d654e",
      "facet_by": "currency"
    }'
  ```
</CodeGroup>

The example above allows you to answer questions like:

* "Of all my USD transactions, how many are in each status?"
* "For this specific customer, how many balances do they have in each currency?""

***

## Faceting on metadata fields

You can also facet on metadata objects.

```bash Facet on metadata fields theme={"system"}
curl -X POST "http://YOUR_BLNK_INSTANCE_URL/search/transactions" \
  -H "X-Blnk-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "q": "*",
    "facet_by": "meta_data.transaction_type,meta_data.payment_method"
  }'
```

<Tip>
  Always use dot notation to access nested metadata fields: `meta_data.field_name`
</Tip>

***

## Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool.

To ask questions or discuss issues, please [contact us](mailto:support@blnkfinance.com) or [join our Discord community](https://discord.gg/7WNv94zPpx).

***

<Tip>
  **Tip:** Connect to Blnk Cloud to see your Core data.

  You can view your transactions, manage identities, create custom reports, invite other team members to collaborate, and perform operations on your Core — all in one dashboard.

  [Check out Blnk Cloud →](https://www.blnkfinance.com/products/cloud)
</Tip>
