ES index API - part 1
Mallikarjun H T
Posted on August 5, 2024
Indices APIs
Index management:
Create Index
Delete Index
Get Index
Indices Exists
Open / Close Index API
Shrink Index
Split Index
Rollover Index
### Mapping management:
Put Mapping
Get Mapping
Get Field Mapping
Types Exists
Alias management:
Index Aliases
Index settings:
Update Indices Settings
Get Settings
Analyze
Index Templates
Monitoring:
Indices Stats
Indices Segments
Indices Recovery
Indices Shard Stores
Status management:
Clear Cache
Refresh
Flush
Force Merge
Create Index
index creation without any mappings
curl -X PUT "localhost:9200/twitter?pretty"
NOTE:
Index name limitations
There are several limitations to what you can name your index. The complete list of limitations are:
Lowercase only
Cannot include \, /, *, ?, ", <, >, |, ` ` (space character), ,, #
Indices prior to 7.0 could contain a colon (:), but that’s been deprecated and won’t be supported in 7.0+
Cannot start with -, _, +
Cannot be . or ..
Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
Index Settings
To update index use this, in this payload we are setting number of shards and no of replicas
curl -X PUT "localhost:9200/twitter?pretty" -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
'
Mappings
setting mappings to an index while creation
curl -X PUT "localhost:9200/test?pretty" -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_doc" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}
}
'
setting Aliases on existing index
curl -XPUT localhost:9200/index1/_alias/index2
multiple Aliases and filtering
curl -X PUT "localhost:9200/test?pretty" -H 'Content-Type: application/json' -d'
{
"aliases" : {
"alias_1" : {},
"alias_2" : {
"filter" : {
"term" : {"user" : "kimchy" }
},
"routing" : "kimchy"
}
}
}
'
💖 💪 🙅 🚩
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.