DEV Community

Mallikarjun H T
Mallikarjun H T

Posted on

ES index API - part 1

Indices APIs

Index management:

Create Index
Delete Index
Get Index
Indices Exists
Open / Close Index API
Shrink Index
Split Index
Rollover Index
Enter fullscreen mode Exit fullscreen mode

### Mapping management:

Put Mapping
Get Mapping
Get Field Mapping
Types Exists
Enter fullscreen mode Exit fullscreen mode

Alias management:

Index Aliases
Enter fullscreen mode Exit fullscreen mode

Index settings:

Update Indices Settings
Get Settings
Analyze
Index Templates
Enter fullscreen mode Exit fullscreen mode

Monitoring:

Indices Stats
Indices Segments
Indices Recovery
Indices Shard Stores
Enter fullscreen mode Exit fullscreen mode

Status management:

Clear Cache
Refresh
Flush
Force Merge
Enter fullscreen mode Exit fullscreen mode

Create Index

index creation without any mappings

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

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)
Enter fullscreen mode Exit fullscreen mode

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
    }
}
'
Enter fullscreen mode Exit fullscreen mode

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" }
            }
        }
    }
}
'
Enter fullscreen mode Exit fullscreen mode

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"
        }
    }
}
'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)