Article Image
Article Image
read

Helpful Elasticsearch APIs

This is a simple post listing the Elasticsearch rest APIs that I use most at work.

List all indices

curl "localhost:9200/_cat/indices"

List all shards

curl "localhost:9200/_cat/shards"

List all elasticserach nodes

curl "localhost:9200/_nodes?pretty"
curl "localhost:9200/_cluster/allocation/explain?pretty"
curl -s 'localhost:9200/_cat/allocation?v'
curl -XPOST localhost:9200/_cluster/reroute?retry_failed=true
curl -X POST localhost:9200/_reindex \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
  "source": {
    "index": "<<index_old_ones_with_data>>",
    "query": {
        "match_all": {}
    }
  },
  "dest": {
    "index": "<<new_index_with_new_mapping>>"
  }
}'
curl -X POST localhost:9200/_reindex \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
  "source": {
    "remote": {
      "host": "http://<some-ip>:9200"
    },
    "index": "<<index_old_ones_with_data>>",
    "query": {
        "match_all": {}
    }
  },
  "dest": {
    "index": "<<new_index_with_new_mapping>>"
  }
}'
curl -X POST "localhost:9200/<index_name>/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "<field>": "<field-value>"
    }
  }
}
'
curl -X POST "localhost:9200/<index_name>/_delete_by_query?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "<field>": "<field-value>"
    }
  }
}
'

PS: I will add description for each soon

Blog Logo

Arun Varghese


Published

Image

Mushycode

My thoughtsdump and playground

Back to Overview