ES Index API- part 2
Mallikarjun H T
Posted on August 5, 2024
Delete Index
curl -X DELETE "localhost:9200/twitter?pretty"
Get Index
this will return mappings and settings if index exist
curl -X GET "localhost:9200/twitter?pretty"
check if index exist
curl -I "localhost:9200/twitter?pretty"
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"
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
}
}
'
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
}
}
'
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": {}
}
}
'
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
}
}'
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"
}
}'
💖 💪 🙅 🚩
Mallikarjun H T
Posted on August 5, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.