# Documents
URL: /api/documents

Index, fetch, and delete documents within a collection.



## Index documents [#index-documents]

<Callout type="info">
  Requires the admin key.
</Callout>

```
POST /collections/{name}/documents
```

Accepts a single flat JSON document object, or a JSON array of documents,
indexed as one batch. `id` is implicit — don't declare it as a schema field.
Indexing an existing `id` again replaces that document.

<Tabs items="['cURL', 'TypeScript', 'Python', 'C#']">
  <Tab value="cURL">
    ```bash
    curl -X POST localhost:8108/collections/products/documents \
      -H 'Content-Type: application/json' \
      -H 'x-tachyon-api-key: your-admin-key' \
      -d '[
        {"id": "1", "title": "Wireless Mouse", "brand": "Logitech", "price": 2999},
        {"id": "2", "title": "Mechanical Keyboard", "brand": "Razer", "price": 8999}
      ]'
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    import { Tachyon } from 'tachyon-sdk';

    const client = new Tachyon({ url: 'http://localhost:8108', apiKey: 'your-admin-key' });

    await client.collection('products').documents.index([
      { id: '1', title: 'Wireless Mouse', brand: 'Logitech', price: 2999 },
      { id: '2', title: 'Mechanical Keyboard', brand: 'Razer', price: 8999 },
    ]);
    ```
  </Tab>

  <Tab value="Python">
    ```python
    from tachyon_sdk import Tachyon

    client = Tachyon(url="http://localhost:8108", api_key="your-admin-key")

    client.collection("products").documents.index([
        {"id": "1", "title": "Wireless Mouse", "brand": "Logitech", "price": 2999},
        {"id": "2", "title": "Mechanical Keyboard", "brand": "Razer", "price": 8999},
    ])
    ```
  </Tab>

  <Tab value="C#">
    ```csharp
    using Tachyon.Sdk;

    var client = new TachyonClient(new TachyonClientOptions { Url = "http://localhost:8108", ApiKey = "your-admin-key" });

    await client.Collection("products").Documents.IndexAsync(
        new Document { ["id"] = "1", ["title"] = "Wireless Mouse", ["brand"] = "Logitech", ["price"] = 2999 },
        new Document { ["id"] = "2", ["title"] = "Mechanical Keyboard", ["brand"] = "Razer", ["price"] = 8999 });
    ```
  </Tab>
</Tabs>

**Response** — a `BatchReport`. Each document in the batch is indexed
independently, so a failure in one doesn't fail the rest:

```json
{
  "num_indexed": 2,
  "num_failed": 0,
  "results": [
    { "success": true, "id": "1", "error": null, "code": null },
    { "success": true, "id": "2", "error": null, "code": null }
  ]
}
```

## Fetch a document [#fetch-a-document]

```
GET /collections/{name}/documents/{id}
```

Requires the admin or search key. Returns the document, or
`404 document_not_found`.

## Delete a document [#delete-a-document]

<Callout type="info">
  Requires the admin key.
</Callout>

```
DELETE /collections/{name}/documents/{id}
```

Takes effect on subsequent searches immediately.
