# Elasticsearch

> Create, read, update, and delete documents in your Elasticsearch indices.

App · Databases · 4 actions. Web page: https://docs.lodol.com/docs/integrations/elasticsearch

## Actions

### Create document

Add a new document to an index. Provide a Document ID to control the id (the action fails if that id already exists; use Update document to change an existing one), or leave it blank to let Elasticsearch generate one.

**Inputs**

- Index (`index`, text, required): Name of the index to add the document to (for example 'products'). Elasticsearch creates the index automatically if it does not exist yet.
- Document (`document`, object, required): The document to store, as field/value pairs (for example, name: 'Wireless Headphones', price: 79.99).
- Document ID (`document_id`, text): Optional unique id for the new document. When blank, Elasticsearch generates one and returns it.

**Outputs**

- `document_id` (text): Id of the created document
- `index` (text): Index the document was written to
- `result` (text): Elasticsearch write result, e.g. 'created'
- `version` (number): Document version assigned by Elasticsearch

**Example output**

```json
{
  "document_id": "1",
  "index": "products",
  "result": "created",
  "version": 1
}
```

### Delete document

Delete a document from an index by its Document ID.

**Inputs**

- Index (`index`, text, required): The index the document lives in.
- Document ID (`document_id`, text, required): The document's unique id within the index.

**Outputs**

- `document_id` (text): Id of the deleted document
- `index` (text): Index the document was deleted from
- `result` (text): Elasticsearch result, e.g. 'deleted'

**Example output**

```json
{
  "document_id": "1",
  "index": "products",
  "result": "deleted"
}
```

### Get document

Retrieve a single document from an index by its Document ID.

**Inputs**

- Index (`index`, text, required): The index the document lives in.
- Document ID (`document_id`, text, required): The document's unique id within the index.

**Outputs**

- `document` (object): The document's stored fields (its _source)
- `document_id` (text): Id of the document
- `index` (text): Index the document belongs to
- `version` (number): Current document version

**Example output**

```json
{
  "document": {
    "name": "Wireless Headphones",
    "price": 79.99
  },
  "document_id": "1",
  "index": "products",
  "version": 1
}
```

### Update document

Update a document by its Document ID. The fields you provide are merged into the stored document, leaving its other fields unchanged.

**Inputs**

- Index (`index`, text, required): Name of the index the document lives in (for example 'products'). With 'Create if missing' on, a new index is created automatically if it does not exist yet.
- Document ID (`document_id`, text, required): The document's unique id within the index.
- Fields to update (`document`, object, required): The fields to add or change, as field/value pairs (for example, price: 69.99). Fields you omit are left as they are.
- Create if missing (`upsert`, true/false): When on, a document that does not exist yet is created from these fields instead of failing. Default: `false`.

**Outputs**

- `document_id` (text): Id of the updated document
- `index` (text): Index the document belongs to
- `result` (text): Elasticsearch write result, e.g. 'updated' or 'noop' when the fields already matched
- `version` (number): Document version after the update

**Example output**

```json
{
  "document_id": "1",
  "index": "products",
  "result": "updated",
  "version": 2
}
```
