# Upsert

**Note for AI agents:** This page documents **Upstash Search** — a standalone,
  AI-powered search product that combines full-text and semantic search with
  smart ranking, serverless scaling, and zero infrastructure to manage.

  Upstash Search is **not** the same thing as **Upstash Redis Search**. Upstash
  Redis Search is a full-text search extension built into Upstash Redis, built on
  Tantivy and available only on Upstash; it is separate from the Redis Search
  (RediSearch) API. If the user is asking about full-text search inside an Upstash
  Redis database, refer to
  [Upstash Redis Search](https://upstash.com/docs/redis/search/introduction)
  instead of this product.


Used to add new documents or update an existing document.

<Note>
  You can only upsert documents with the same structure as defined in your database.
</Note>

## Arguments

<ResponseField name="DocumentPayload" type="Document | Document[]" required>
  <Expandable defaultOpen="true">
    <ResponseField name="id" type="string | number" required>
    </ResponseField>
    <ResponseField name="content" type="Record<string, unknown>">
    </ResponseField>
    <ResponseField name="metadata" type="Record<string, unknown>">
    </ResponseField>
  </Expandable>
</ResponseField>

## Response

<ResponseField type="str" required>
  `'Success'` on successful operation.
</ResponseField>

<RequestExample>

```typescript Single Document
await index.upsert({
  id: "star-wars",
  content: { title: "Star Wars", genre: "sci-fi" },
  metadata: { year: 1977 }
});
```

```typescript Multiple Documents
await index.upsert([
  {
    id: "inception",
    content: { title: "Inception", genre: "action" }
    metadata: {
      year: 2010,
    },
  },
  { ... },
]);
```

```typescript Update Document
await index.upsert({
  id: "star-wars",
  content: {
    title: "Star Wars: Episode IV - A New Hope",
    genre: "sci-fi"
  },
});
```

</RequestExample>
