Popular APIs

This page contains sample requests for popular OpenSearch operations.


Table of contents

  1. Create index with non-default settings
  2. Index a document with a random ID
  3. Index a document with a specific ID
  4. Index several documents at once
  5. List all indices
  6. Open or close all indices that match a pattern
  7. Delete all indices that match a pattern
  8. Create an index alias
  9. List all aliases
  10. Search an index or all indices that match a pattern
  11. Get cluster settings, including defaults
  12. Change disk watermarks (or other cluster settings)
  13. Get cluster health
  14. List nodes in the cluster
  15. Get node statistics
  16. Get snapshots in a repository
  17. Take a snapshot
  18. Restore a snapshot

Create index with non-default settings

  1. PUT my-logs
  2. {
  3. "settings": {
  4. "number_of_shards": 4,
  5. "number_of_replicas": 2
  6. },
  7. "mappings": {
  8. "properties": {
  9. "title": {
  10. "type": "text"
  11. },
  12. "year": {
  13. "type": "integer"
  14. }
  15. }
  16. }
  17. }

Index a document with a random ID

  1. POST my-logs/_doc
  2. {
  3. "title": "Your Name",
  4. "year": "2016"
  5. }

Index a document with a specific ID

  1. PUT my-logs/_doc/1
  2. {
  3. "title": "Weathering with You",
  4. "year": "2019"
  5. }

Index several documents at once

The blank line at the end of the request body is required. If you omit the _id field, OpenSearch generates a random ID.

  1. POST _bulk
  2. { "index": { "_index": "my-logs", "_id": "2" } }
  3. { "title": "The Garden of Words", "year": 2013 }
  4. { "index" : { "_index": "my-logs", "_id" : "3" } }
  5. { "title": "5 Centimeters Per Second", "year": 2007 }

List all indices

  1. GET _cat/indices?v&expand_wildcards=all

Open or close all indices that match a pattern

  1. POST my-logs*/_open
  2. POST my-logs*/_close

Delete all indices that match a pattern

  1. DELETE my-logs*

Create an index alias

This request creates the alias my-logs-today for the index my-logs-2019-11-13.

  1. PUT my-logs-2019-11-13/_alias/my-logs-today

List all aliases

  1. GET _cat/aliases?v

Search an index or all indices that match a pattern

  1. GET my-logs/_search?q=test
  2. GET my-logs*/_search?q=test

Get cluster settings, including defaults

  1. GET _cluster/settings?include_defaults=true

Change disk watermarks (or other cluster settings)

  1. PUT _cluster/settings
  2. {
  3. "transient": {
  4. "cluster.routing.allocation.disk.watermark.low": "80%",
  5. "cluster.routing.allocation.disk.watermark.high": "85%"
  6. }
  7. }

Get cluster health

  1. GET _cluster/health

List nodes in the cluster

  1. GET _cat/nodes?v

Get node statistics

  1. GET _nodes/stats

Get snapshots in a repository

  1. GET _snapshot/my-repository/_all

Take a snapshot

  1. PUT _snapshot/my-repository/my-snapshot

Restore a snapshot

  1. POST _snapshot/my-repository/my-snapshot/_restore
  2. {
  3. "indices": "-.opendistro_security",
  4. "include_global_state": false
  5. }