Upload data for index creation
In Advanced Managed Search (OpenSearch), an index is automatically created during the process of uploading (indexing) documents.
This section explains how to upload a single document and bulk documents using the OpenSearch API.
Prerequisites
Before starting the data upload, check the following.
- Confirm that the Advanced Managed Search cluster is in Running state
- Check the endpoint on the cluster details page
- Prepare the master user account credentials configured during cluster creation
- Prepare an environment capable of sending OpenSearch API requests (such as curl)
Index naming rules
When creating an index in OpenSearch, the following naming rules must be followed.
- Letters in the index name must be lowercase (a–z).
- It cannot include spaces (
). - The following special characters cannot be used.
\ / * ? " < > | , # : .(dot) or..cannot be used alone as the index name.- The index name can include
_,-, and numbers (0–9), but cannot begin with_,-, or+. - The maximum length is 255 bytes in UTF-8.
Because the index name is used as part of the URL path, document upload requests may fail if the naming rules are violated.
Upload single document (index)
OpenSearch allows uploading a single document through a REST API. If the specified index does not exist, it is automatically created when the document is uploaded.
curl -X PUT "https://<cluster-endpoint>/movies/_doc/1" \
-u '<master-user>:<password>' \
-H "Content-Type: application/json" \
-d '{
"title": "The Matrix",
"year": 1999,
"genre": "Sci-Fi"
}'
| Item | Description |
|---|---|
movies | Index name |
_doc | Document API endpoint |
1 | Unique document ID |
| Request body (JSON) | Document data to index |
If the request succeeds, the document is stored in OpenSearch and becomes searchable after a refresh.
Upload bulk documents
curl -X POST "https://<cluster-endpoint>/_bulk" \
-u '<master-user>:<password>' \
-H "Content-Type: application/x-ndjson" \
-d '
{ "index": { "_index": "movies", "_id": "2" } }
{ "title": "Inception", "year": 2010, "genre": "Sci-Fi" }
{ "index": { "_index": "movies", "_id": "3" } }
{ "title": "Interstellar", "year": 2014, "genre": "Sci-Fi" }
'
- A Bulk request alternates between an action metadata line and a document data line.
- Each JSON object must be separated by a newline character (
\n).
The last line of a Bulk API request must also include a newline character. If the format is incorrect, the request may fail.
Verify uploaded data
You can verify the uploaded data in the following ways.
- Access OpenSearch Dashboards to check indexes and documents
- Retrieve documents using the search API
curl -X GET "https://<cluster-endpoint>/movies/_search" \
-u '<master-user>:<password>'