DEV Community

Mallikarjun H T
Mallikarjun H T

Posted on

ES Index API- part 2

Delete Index

curl -X DELETE "localhost:9200/twitter?pretty"
Enter fullscreen mode Exit fullscreen mode

Get Index

this will return mappings and settings if index exist

curl -X GET "localhost:9200/twitter?pretty"
Enter fullscreen mode Exit fullscreen mode

check if index exist

curl -I "localhost:9200/twitter?pretty"
Enter fullscreen mode Exit fullscreen mode

Open / Close Index API

use this with caution - like updating or to prevent new document insertion - search will work but indexing will not work

curl -X POST "localhost:9200/my_index/_close?pretty"
curl -X POST "localhost:9200/my_index/_open?pretty"
Enter fullscreen mode Exit fullscreen mode

Shrink Index

use this to reduce the number of shards for version < 7 it is 5 and above it is 1 shard.

Preparing an index for shrinking

curl -X PUT "localhost:9200/my_source_index/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.routing.allocation.require._name": "shrink_node_name", 
    "index.blocks.write": true 
  }
}
'
Enter fullscreen mode Exit fullscreen mode

Shrinking an index

curl -X POST "localhost:9200/my_source_index/_shrink/my_target_index?copy_settings=true&pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.routing.allocation.require._name": null, 
    "index.blocks.write": null 
  }
}
'
Enter fullscreen mode Exit fullscreen mode

Shrinking with settings

curl -X POST "localhost:9200/my_source_index/_shrink/my_target_index?copy_settings=true&pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.number_of_replicas": 1,
    "index.number_of_shards": 1, 
    "index.codec": "best_compression" 
  },
  "aliases": {
    "my_search_indices": {}
  }
}
'
Enter fullscreen mode Exit fullscreen mode

Rollover Index

Defining the new index

curl -X PUT "localhost:9200/logs-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "aliases": {
    "logs_write": {}
  }
}'

curl -X POST "localhost:9200/logs_write/_rollover?pretty" -H 'Content-Type: application/json' -d'
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  },
  "settings": {
    "index.number_of_shards": 2
  }
}'
Enter fullscreen mode Exit fullscreen mode

Dry run

curl -X PUT "localhost:9200/logs-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "aliases": {
    "logs_write": {}
  }
}'

curl -X POST "localhost:9200/logs_write/_rollover?dry_run&pretty" -H 'Content-Type: application/json' -d'
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  }
}'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)