Ingest your data into OpenSearch

There are several ways to ingest data into OpenSearch:

  • Ingest individual documents. For more information, see Indexing documents.
  • Index multiple documents in bulk. For more information, see Bulk indexing.
  • Use Data Prepper—an OpenSearch server-side data collector that can enrich data for downstream analysis and visualization. For more information, see Data Prepper.
  • Use other ingestion tools. For more information, see OpenSearch tools.

Bulk indexing

To index documents in bulk, you can use the Bulk API. For example, if you want to index several documents into the students index, send the following request:

  1. POST _bulk
  2. { "create": { "_index": "students", "_id": "2" } }
  3. { "name": "Jonathan Powers", "gpa": 3.85, "grad_year": 2025 }
  4. { "create": { "_index": "students", "_id": "3" } }
  5. { "name": "Jane Doe", "gpa": 3.52, "grad_year": 2024 }

copy

Experiment with sample data

OpenSearch provides a fictitious e-commerce dataset that you can use to experiment with REST API requests and OpenSearch Dashboards visualizations. You can create an index and define field mappings by downloading the corresponding dataset and mapping files.

Create a sample index

Use the following steps to create a sample index and define field mappings for the document fields:

  1. Download ecommerce-field_mappings.json. This file defines a mapping for the sample data you will use.

    To use cURL, send the following request:

    1. curl -O https://raw.githubusercontent.com/opensearch-project/documentation-website/2.16/assets/examples/ecommerce-field_mappings.json

    copy

    To use wget, send the following request:

    1. wget https://raw.githubusercontent.com/opensearch-project/documentation-website/2.16/assets/examples/ecommerce-field_mappings.json

    copy

  2. Download ecommerce.json. This file contains the index data formatted so that it can be ingested by the Bulk API:

    To use cURL, send the following request:

    1. curl -O https://raw.githubusercontent.com/opensearch-project/documentation-website/2.16/assets/examples/ecommerce.json

    copy

    To use wget, send the following request:

    1. wget https://raw.githubusercontent.com/opensearch-project/documentation-website/2.16/assets/examples/ecommerce.json

    copy

  3. Define the field mappings provided in the mapping file:

    1. curl -H "Content-Type: application/x-ndjson" -X PUT "https://localhost:9200/ecommerce" -ku admin:<custom-admin-password> --data-binary "@ecommerce-field_mappings.json"

    copy

  4. Upload the documents using the Bulk API:

    1. curl -H "Content-Type: application/x-ndjson" -X PUT "https://localhost:9200/ecommerce/_bulk" -ku admin:<custom-admin-password> --data-binary "@ecommerce.json"

    copy

Query the data

Query the data using the Search API. The following query searches for documents in which customer_first_name is Sonya:

  1. GET ecommerce/_search
  2. {
  3. "query": {
  4. "match": {
  5. "customer_first_name": "Sonya"
  6. }
  7. }
  8. }

copy

Visualize the data

To learn how to use OpenSearch Dashboards to visualize the data, see the OpenSearch Dashboards quickstart guide.

Further reading

Next steps