# OpenSearch

{% hint style="info" %}
The following documentation is for **OpenSearch v2.0.1** *(BDK)*.
{% endhint %}

## Overview

OpenSearch is a distributed, open-source search and analytics suite used for a broad set of use cases like real-time application monitoring, log analytics, and website search. This integration enables automated index management, document indexing, search operations, and data analytics workflows. Leverage powerful search capabilities and streamline data discovery processes.

## Prerequisites

### 1. Required Books

The following Book(s) need to be added to your agent so it can learn and understand the automation procedures defined within them:

* **OpenSearch**

#### How to Add the Book(s)

1. Go to **Books** → **All Books**.
2. Search for the name of the book and click on it.
3. Click on <kbd>**Install**</kbd> or <kbd>**Add Connection**</kbd> to add the book to your agent.
4. If adding a connection, you'll be prompted for [**connectivity**](#connectivity) details.

## Connectivity

This section outlines the available methods for connecting to the Book, along with the required configuration details for each.

### Connect using Hosts, Username and Password

Connect via http credentials

| Label    | Description                | Type        |
| -------- | -------------------------- | ----------- |
| Hosts    | comma-separated hosts      | `text`      |
| Username | the username for http auth | `text`      |
| Password | The password for http auth | `sensitive` |

## Procedures

### to create a (document) in *opensearch*

Create a document in opensearch

**Input Concepts**

| Concept       | Description                       | Type   | Required | Default Value |
| ------------- | --------------------------------- | ------ | -------- | ------------- |
| `index name`  | The name of the index.            | `text` | Yes      | (no default)  |
| `document`    | The document to be indexed.       | `json` | Yes      | (no default)  |
| `document id` | The optional ID for the document. | `text` | No       | (no default)  |

**Output Concepts**

| Concept                            | Description                 | Type                  |
| ---------------------------------- | --------------------------- | --------------------- |
| [`document`](#opensearch-document) | the result of the operation | `opensearch document` |

**Examples**

create a document in opensearch

```generic
create a json
use the above as the document
the document's "title" is "My New Document"
create the document in opensearch
    the index name is "my_index"
```

create a document in opensearch with a specific id

```generic
create a json
use the above as the document
the document's "title" is "My New Document"
create the document in opensearch
    the index name is "my_index"
    the document id is "my-custom-id"
```

### to delete a document from *opensearch*

Delete a document from opensearch

**Input Concepts**

| Concept                            | Description             | Type                  | Required | Default Value |
| ---------------------------------- | ----------------------- | --------------------- | -------- | ------------- |
| [`document`](#opensearch-document) | The document to delete. | `opensearch document` | Yes      | (no default)  |

**Examples**

```generic
get a document from opensearch
    the document id is "my-document-id"
delete the document from opensearch
```

### to get a (document) from *opensearch*

Get a document from opensearch by its ID

**Input Concepts**

| Concept       | Description                         | Type   | Required | Default Value |
| ------------- | ----------------------------------- | ------ | -------- | ------------- |
| `index name`  | The name of the index.              | `text` | Yes      | (no default)  |
| `document id` | The ID of the document to retrieve. | `text` | Yes      | (no default)  |

**Output Concepts**

| Concept                            | Description                   | Type                  |
| ---------------------------------- | ----------------------------- | --------------------- |
| [`document`](#opensearch-document) | the OpensearchDocument object | `opensearch document` |

**Examples**

get an document from opensearch

```generic
get a document from opensearch
    the index name is "my_index"
    the document id is "my-document-id"
```

### to query some (documents) from *opensearch*

![FILTER - CAPABLE](https://img.shields.io/static/v1?label=FILTER\&message=CAPABLE\&color=blue)

Query documents from Opensearch

**Input Concepts**

| Concept      | Description                                                          | Type                                       | Required | Default Value                                                   |
| ------------ | -------------------------------------------------------------------- | ------------------------------------------ | -------- | --------------------------------------------------------------- |
| `index name` | single index name, or comma separated index or aliases to search on. | `text`                                     | Yes      | (no default)                                                    |
| `query type` | the type of query to perform                                         | `enum[fuzzy, match, prefix, simple, term]` | No       | {'class\_name': 'QueryType', 'name': 'MATCH', 'value': 'match'} |

**Output Concepts**

| Concept                             | Description                            | Type                  |
| ----------------------------------- | -------------------------------------- | --------------------- |
| [`documents`](#opensearch-document) | the list of OpensearchDocument objects | `opensearch document` |

**Examples**

query some documents from opensearch

```generic
query some documents from opensearch
    the index name is "my_index"
```

query some documents from opensearch with filter expression

```generic
query some documents from opensearch whose title is "Mulholland Drive"
    the index name is "movies"
    the filter expression is "title:Mulholland Drive"
```

query some documents from opensearch with filter expression and fuzzy query type

```generic
query some documents from opensearch whose title is "Mulholland Drive"
    the index name is "movies"
    the filter expression is "title:Mulholland Drive"
    the query type is "FUZZY"
    the limit is 10
    the offset is 0
```

### to update a (document) in *opensearch*

Update a document in opensearch

**Input Concepts**

| Concept                            | Description             | Type                  | Required | Default Value |
| ---------------------------------- | ----------------------- | --------------------- | -------- | ------------- |
| [`document`](#opensearch-document) | The document to update. | `opensearch document` | Yes      | (no default)  |

**Output Concepts**

| Concept                            | Description          | Type                  |
| ---------------------------------- | -------------------- | --------------------- |
| [`document`](#opensearch-document) | the updated document | `opensearch document` |

**Examples**

```generic
get a document from opensearch
    the document id is "my-document-id"
the document's source's name is "John"
update the document in opensearch
    the document id is "my-document-id"
```

## Concepts

### Opensearch document

Represents an Document in Opensearch.

| Field Name   | Description                                    | Type   |
| ------------ | ---------------------------------------------- | ------ |
| `id`         | The ID of the document.                        | `text` |
| `index_name` | The name of the index the document belongs to. | `text` |
| `source`     | The document values.                           | `json` |
