# ES Billing cURL Examples (v1)

Use env vars:
- `ES_URL`
- `ES_API_KEY`
- `ES_INDEX=customer_subscription_v1`

## Payment trend buckets from nested orders
```bash
curl -sS -H "Authorization: ApiKey $ES_API_KEY" "$ES_URL/$ES_INDEX/_search" \
  -H 'Content-Type: application/json' -d '{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {"term": {"app_id": 1004}},
        {"nested": {"path": "orders", "query": {"bool": {"must": [
          {"range": {"orders.order_created_at": {"gte": "2026-02-05 00:00:00", "lte": "2026-05-05 23:59:59"}}}
        ]}}}}
      ]
    }
  },
  "aggs": {
    "orders_nested": {
      "nested": {"path": "orders"},
      "aggs": {
        "per_day": {
          "date_histogram": {"field": "orders.order_created_at", "calendar_interval": "day"}
        }
      }
    }
  }
}'
```
