[Yandex Cloud documentation](../../index.md) > [Yandex Data Transfer](../index.md) > [Tutorials](index.md) > Uploading data to Object Storage > OpenSearch to Object Storage

# Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer

# Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer

With Data Transfer, you can transfer data from a Managed Service for OpenSearch cluster to Object Storage.

To transfer data:

1. [Set up your infrastructure](#prepare-infrastructure).
1. [Prepare your test data](#prepare-data).
1. [Prepare and activate the transfer](#prepare-transfer).
1. [Test the transfer](#verify-transfer).

If you no longer need the resources you created, [delete them](#clear-out).


## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

### Required paid resources {#paid-resources}

* Managed Service for OpenSearch cluster: use of computing resources, storage and backup size (see [Managed Service for OpenSearch pricing](../../managed-opensearch/pricing.md)).
* Public IP addresses if public access is enabled for cluster hosts (see [Yandex Virtual Private Cloud pricing](../../vpc/pricing.md)).
* Object Storage bucket: use of storage, data operations (see [Object Storage pricing](../../storage/pricing.md)).


## Set up your infrastructure {#prepare-infrastructure}


{% list tabs group=instructions %}

- Manually {#manual}

    1. [Create a Managed Service for OpenSearch cluster](../../managed-opensearch/operations/cluster-create.md) of any suitable configuration with publicly accessible hosts.

        {% note info %}
        
        Public access to cluster hosts is required if you plan to connect to the cluster via the internet. This connection option is simpler and is recommended for the purposes of this guide. You can connect to non-public hosts as well but only from Yandex Cloud virtual machines located in the same cloud network as the cluster.
        
        {% endnote %}

    1. If there are security groups in your cluster, make sure they are configured correctly and allow connections to the [Managed Service for OpenSearch cluster](../../managed-opensearch/operations/connect/index.md#configuring-security-groups).

    1. [Get an SSL certificate](../../managed-opensearch/operations/connect/index.md#ssl-certificate) to connect to the Managed Service for OpenSearch cluster.

    1. [Create an Object Storage bucket](../../storage/operations/buckets/create.md).

    
    1. [Create a service account](../../iam/operations/sa/create.md#create-sa) with the `storage.editor` role. The transfer will use it to access the bucket.


- Terraform {#tf}

    1. If you do not have Terraform yet, [install it](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
    1. [Get the authentication credentials](../../tutorials/infrastructure-management/terraform-quickstart.md#get-credentials). You can add them to environment variables or specify them later in the provider configuration file.
    1. [Configure and initialize a provider](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). There is no need to create a provider configuration file manually, you can [download it](https://github.com/yandex-cloud-examples/yc-terraform-provider-settings/blob/main/provider.tf).
    1. Place the configuration file in a separate working directory and [specify the parameter values](../../tutorials/infrastructure-management/terraform-quickstart.md#configure-provider). If you did not add the authentication credentials to environment variables, specify them in the configuration file.

    1. Download the [opensearch-to-object-storage.tf](https://github.com/yandex-cloud-examples/yc-data-transfer-from-opensearch-to-object-storage/blob/main/opensearch-to-object-storage.tf) configuration file to the same working directory.

        This file describes:

        * [Network](../../vpc/concepts/network.md#network).
        * [Subnet](../../vpc/concepts/network.md#subnet).
        * [Security group](../../vpc/concepts/security-groups.md) for connecting to a Managed Service for OpenSearch cluster.
        * Service account with the `storage.editor` role.
        * Managed Service for OpenSearch cluster.
        * Object Storage target bucket.
        * Endpoints.
        * Transfer.

    1. In the `opensearch-to-object-storage.tf` file, specify the following settings:

        * `folder_id`: [Folder ID](../../resource-manager/operations/folder/get-id.md).
        * `mos_version`: OpenSearch version.
        * `mos_password`: User password of the OpenSearch cluster owner.
        * `bucket_name`: Bucket name consistent with the [naming conventions](../../storage/concepts/bucket.md#naming).
        * `profile_name`: Name of your CLI profile.

          If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    1. Validate your Terraform configuration files using this command:

        ```bash
        terraform validate
        ```

        Terraform will display any configuration errors detected in your files.

    1. Create the required infrastructure:

        1. Run this command to view the planned changes:
        
           ```bash
           terraform plan
           ```
        
           If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
        
        1. If everything looks correct, apply the changes:
           1. Run this command:
        
              ```bash
              terraform apply
              ```
        
           1. Confirm updating the resources.
           1. Wait for the operation to complete.

        All the required resources will be created in the specified folder. You can check resource availability and their settings in the [management console](https://console.yandex.cloud).

{% endlist %}

## Prepare your test data {#prepare-data}

1. [Connect to the Managed Service for OpenSearch source cluster](../../managed-opensearch/operations/connect/index.md).

1. Create a test index named `people` and define its schema:

    ```bash
    curl --user admin:<password> \
         --cacert ~/.opensearch/root.crt \
         --header 'Content-Type: application/json' \
         --request PUT 'https://<address_of_OpenSearch_host_with_DATA_role>:9200/people' && \
    curl --user admin:<password> \
         --cacert ~/.opensearch/root.crt \
         --header 'Content-Type: application/json' \
         --request PUT 'https://<address_of_OpenSearch_host_with_DATA_role>:9200/people/_mapping?pretty' \
         --data'
         {
               "properties": {
                  "name": {"type": "text"},
                  "age": {"type": "integer"}
               }
         }
         '
    ```

1. Populate the test index with data:

    ```bash
    curl --user admin:<password> \
         --cacert ~/.opensearch/root.crt \
         --header 'Content-Type: application/json' \
         --request POST 'https://<address_of_OpenSearch_host_with_DATA_role>:9200/people/_doc/?pretty' \
         --data'
         {
               "name" : "Alice",
               "age" : "30"
         }
         ' && \
    curl --user admin:<password> \
         --cacert ~/.opensearch/root.crt \
         --header 'Content-Type: application/json' \
         --request POST 'https://<address_of_OpenSearch_host_with_DATA_role>:9200/people/_doc/?pretty' \
         --data'
         {
               "name" : "Robert",
               "age" : "32"
         }
         '
    ```

1. Optionally, check the data in the test index:

    ```bash
    curl --user admin:<password> \
         --cacert ~/.opensearch/root.crt \
         --header 'Content-Type: application/json' \
         --request GET 'https://<address_of_OpenSearch_host_with_DATA_role>:9200/people/_search?pretty'
    ```

## Prepare and activate a transfer {#prepare-transfer}

1. [Create a target endpoint](../operations/endpoint/target/object-storage.md) of the `Object Storage` type with the following settings:

    * **Bucket**: `<name_of_previously_created_bucket>`.

    
    * **Service account**: `<name_of_previously_created_service_account>`.


    * **Serialization format**: `JSON`.
    * **Encoding format**: `Uncompressed`.
    * **Folder name**: `from_MOS`.

1. [Create a source endpoint](../operations/endpoint/source/opensearch.md#endpoint-settings) of the `OpenSearch` type with the following settings:

    * **Connection type**: `Managed Service for OpenSearch cluster`.
    * **Managed Service for OpenSearch cluster**: Select your Managed Service for OpenSearch cluster from the list.
    * **User**: `admin`.
    * **Password**: `<user_password>`.

1. Create a transfer:

    {% list tabs group=instructions %}

    - Manually {#manual}

      1. [Create a transfer](../operations/transfer.md#create) of the **Snapshot** type that will use the endpoints you created.

      1. [Activate the transfer](../operations/transfer.md#activate).

    - Terraform {#tf}

      1. In the `opensearch-to-object-storage.tf` file, specify the values of the following variables:

          * `target_endpoint_id`: Target endpoint ID.
          * `source_endpoint_id`: Source endpoint ID.
          * `transfer_enabled`: Set to `1` to create a transfer.

      1. Validate your Terraform configuration files using this command:

          ```bash
          terraform validate
          ```

          Terraform will display any configuration errors detected in your files.

      1. Create the required infrastructure:

          1. Run this command to view the planned changes:
          
             ```bash
             terraform plan
             ```
          
             If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
          
          1. If everything looks correct, apply the changes:
             1. Run this command:
          
                ```bash
                terraform apply
                ```
          
             1. Confirm updating the resources.
             1. Wait for the operation to complete.

          The transfer will be activated automatically upon creation.

    {% endlist %}

## Test the transfer {#verify-transfer}

Make sure the data has been transferred from the Managed Service for OpenSearch cluster to the Object Storage bucket:

1. Wait for the transfer status to change to **Completed**.
1. In the [management console](https://console.yandex.cloud), select the folder containing your bucket.
1. Navigate to **Object Storage**.
1. Select the bucket from the list.
1. Navigate to the **Objects** tab.
1. Make sure the Object Storage bucket contains the `from_MOS` folder with the test data JSON file.

## Delete the resources you created {#clear-out}

To minimize resource consumption, delete the resources you no longer need:

1. [Delete the transfer](../operations/transfer.md#delete).
1. [Delete the endpoints](../operations/endpoint/index.md#delete).
1. [Delete](../../storage/operations/objects/delete.md) the `from_MOS` folder from the bucket you created.
1. Delete the other resources depending on how you created them:

   {% list tabs group=instructions %}

   - Manually {#manual}

       1. [Delete the Object Storage bucket](../../storage/operations/buckets/delete.md).
       1. [Delete the Managed Service for OpenSearch cluster](../../managed-opensearch/operations/cluster-delete.md).

       
       1. [Delete the service account](../../iam/operations/sa/delete.md).


   - Terraform {#tf}

       1. In the terminal window, go to the directory containing the infrastructure plan.
       
           {% note warning %}
       
           Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
       
           {% endnote %}
       
       1. Delete resources:
       
           1. Run this command:
       
               ```bash
               terraform destroy
               ```
       
           1. Confirm deleting the resources and wait for the operation to complete.
       
           All the resources described in the Terraform manifests will be deleted.

   {% endlist %}