51
Elasticsearch Reference Indices APIs

Indices APIs - Elasticsearch Reference

Embed Size (px)

DESCRIPTION

Elasticsearch 레퍼런스의 Indices API에 대한 발표 자료

Citation preview

Page 1: Indices APIs - Elasticsearch Reference

Elasticsearch Reference

Indices APIs

Page 2: Indices APIs - Elasticsearch Reference

Postman Shared Collection

http://goo.gl/Px9jf2

Page 3: Indices APIs - Elasticsearch Reference

Indices

Page 4: Indices APIs - Elasticsearch Reference

Create Indices

$ curl -XPUT localhost:9200/twitter/

$ curl -XPUT localhost:9200/twitter/ -d 'index : number_of_shards : 3 number_of_replicas : 2'

More about Index Settings => Index Modules

Page 5: Indices APIs - Elasticsearch Reference

$ curl -XPUT localhost:9200/twitter/ -d '{ "settings" : { "index" : { "number_of_shards" : 3, "number_of_replicas" : 2 } }}'

or, simply

$ curl -XPUT localhost:9200/twitter/ -d '{ "settings" : { "number_of_shards" : 3, "number_of_replicas" : 2 }}'

Page 6: Indices APIs - Elasticsearch Reference

Delete Indices

$ curl -XDELETE localhost:9200/twitter/

Page 7: Indices APIs - Elasticsearch Reference

Indices Exist?

$ curl -XHEAD localhost:9200/twitter

Page 8: Indices APIs - Elasticsearch Reference

Open/Close Indices

$ curl -XPOST localhost:9200/twitter/_close

$ curl -XPOST localhost:9200/twitter/_open

Page 9: Indices APIs - Elasticsearch Reference

Update Index Settings

$ curl -XPUT localhost:9200/twitter/_settings -d '{ "index" : { "number_of_replicas" : 4 }}'

Page 10: Indices APIs - Elasticsearch Reference

Get Index Settings

$ curl -XGET localhost:9200/twitter/_settings

Supports multiple indices.

$ curl -XGET localhost:9200/twitter,kimchy/_settings

$ curl -XGET localhost:9200/_all/_settings

$ curl -XGET localhost:9200/2013-*/_settings

Page 11: Indices APIs - Elasticsearch Reference

Filter settings with prefix and name options.

$ curl -XGET localhost:9200/twitter/_settings?prefix=index.

$ curl -XGET localhost:9200/_all/_settings?prefix=index.routing.allocation.

$ curl -XGET localhost:9200/2013-*/_settings?name=index.merge.*

$ curl -XGET localhost:9200/2013-*/_settings/index.merge.*

Page 12: Indices APIs - Elasticsearch Reference

Mappings

Page 13: Indices APIs - Elasticsearch Reference

Put Mappings

$ curl -XPUT localhost:9200/twitter/tweet/_mapping -d '{ "tweet" : { "properties" : { "message" : {"type" : "string", "store" : true } } }}'

More about Mappings => Mapping

Page 14: Indices APIs - Elasticsearch Reference

Supports multi indices.

$ curl -XPUT localhost:9200/twitter,facebook/tweet/_mapping -d '{ "tweet" : { "properties" : { "message" : {"type" : "string", "store" : true } } }}'

Page 15: Indices APIs - Elasticsearch Reference

Get Mappings

$ curl -XGET localhost:9200/twitter/tweet/_mapping

Also, supports multi indices and types.

$ curl -XGET localhost:9200/twitter,facebook/_mapping

$ curl -XGET localhost:9200/_all/tweet,post/_mapping

Page 16: Indices APIs - Elasticsearch Reference

Get Field Mappings

$ curl -XGET localhost:9200/twitter/tweet/_mapping/field/text

Of course, also supports multi indices, types and fields.

$ curl -XGET localhost:9200/twitter,facebook/_mapping/field/message

$ curl -XGET localhost:9200/_all/tweet,post/_mapping/field/message,user.id

$ curl -XGET localhost:9200/_all/tw*/_mapping/field/*.id

Page 17: Indices APIs - Elasticsearch Reference

Types Exist?

$ curl -XHEAD localhost:9200/twitter/tweet

Page 18: Indices APIs - Elasticsearch Reference

Delete Mappings

$ curl -XDELETE localhost:9200/twitter/tweet/_mapping$ curl -XDELETE localhost:9200/twitter/tweet

Deleting Mapping == Deleting Types

Page 19: Indices APIs - Elasticsearch Reference

Aliases

Page 20: Indices APIs - Elasticsearch Reference

Index Aliases

Alias == View (in RDB)

Add Aliases

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "add" : { "index" : "twitter", "alias" : "alias1" } } ]}'

Page 21: Indices APIs - Elasticsearch Reference

Get Aliases

$ curl -XGET localhost:9200/_aliases

Remove Aliases

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "remove" : { "index" : "twitter", "alias" : "alias1" } } ]}'

Page 22: Indices APIs - Elasticsearch Reference

Multi Actions

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "remove" : { "index" : "twitter", "alias" : "alias1" } }, { "add" : { "index" : "twitter", "alias" : "alias2" } } ]}'

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "add" : { "index" : "twitter", "alias" : "alias1" } }, { "add" : { "index" : "facebook", "alias" : "alias1" } } ]}'

Page 23: Indices APIs - Elasticsearch Reference

Filtered Aliases

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "add" : { "index" : "twitter", "alias" : "alias2", "filter" : { "term" : { "user" : "kimchy" } } } } ]}'

More about Filters => Query DSL

Page 24: Indices APIs - Elasticsearch Reference

Routing

Filter by routing values

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "add" : { "index" : "twitter", "alias" : "alias1", "routing" : "1" } } ]}'

Page 25: Indices APIs - Elasticsearch Reference

Different routing values for searching and indexing.

$ curl -XPOST localhost:9200/_aliases -d '{ "actions" : [ { "add" : { "index" : "twitter", "alias" : "alias2", "search_routing" : "1,2", "index_routing" : "2" } } ]}'

Page 26: Indices APIs - Elasticsearch Reference

Analyze

Page 27: Indices APIs - Elasticsearch Reference

Analyze

Performs the analysis process on a text and return the tokens breakdown of the text.

$ curl -XPOST localhost:9200/_analyze?analyzer=standard -d 'this is a test'

$ curl -XPOST 'localhost:9200/_analyze?tokenizer=keyword&filters=lowercase' \-d 'this is a test'

$ curl -XPOST 'localhost:9200/_analyze?tokenizer=keyword&token_filters=lowercase&char_filters=html_strip' -d 'this is a <b>test</b>'

$ curl -XGET localhost:9200/twitter/_analyze?text=this+is+a+test

Page 28: Indices APIs - Elasticsearch Reference

Templates

Page 29: Indices APIs - Elasticsearch Reference

Index Templates

Index templates allow to define templates that will automatically be applied to new indices created.

Page 30: Indices APIs - Elasticsearch Reference

Create Templates

$ curl -XPUT localhost:9200/_template/template_1 -d '{ "template" : "te*", "settings" : { "number_of_shards" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : false } } }}'

Will be applied to the indices with te* name pattern.

Page 31: Indices APIs - Elasticsearch Reference

{index} placeholder

$ curl -XPUT localhost:9200/_template/template_1 -d '{ "template" : "te*", "settings" : { "number_of_shards" : 1 }, "aliases" : { "alias1" : {}, "alias2" : { "filter" : { "term" : {"user" : "kimchy" } }, "routing" : "kimchy" }, "{index}-alias" : {} }}'

Page 32: Indices APIs - Elasticsearch Reference

Delete Templates

$ curl -XDELETE localhost:9200/_template/template_1

Get Templates

$ curl -XGET localhost:9200/_template/template_1$ curl -XGET localhost:9200/_template/temp*$ curl -XGET localhost:9200/_template/template_1,template_2$ curl -XGET localhost:9200/_template/

Page 33: Indices APIs - Elasticsearch Reference

Multiple Template Matching by order

$ curl -XPUT localhost:9200/_template/template_1 -d '{ "template" : "*", "order" : 0, "settings" : { "number_of_shards" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : false } } }}'

$ curl -XPUT localhost:9200/_template/template_2 -d '{ "template" : "te*", "order" : 1, "settings" : { "number_of_shards" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : true } } }}'

Page 34: Indices APIs - Elasticsearch Reference

Config

Index templates can also be placedwithin config/templates directory.

Page 35: Indices APIs - Elasticsearch Reference

Warmers

Page 36: Indices APIs - Elasticsearch Reference

Warmers

Index warming allows to run registered search requests to warm up the index before it is available for search.

Warmup searches typically include requests that require heavy loading of data, such as faceting or sorting on specific fields.

Page 37: Indices APIs - Elasticsearch Reference

Index Creation with Warmers

$ curl -XPUT localhost:9200/test -d '{ "warmers" : { "warmer_1" : { "types" : [], "source" : { "query" : { "match_all" : {} }, "facets" : { "facet_1" : { "terms" : { "field" : "field" } } } } } }}'

Page 38: Indices APIs - Elasticsearch Reference

Put Warmers

$ curl -XPUT localhost:9200/test/_warmer/warmer_1 -d '{ "query" : { "match_all" : {} }, "facets" : { "facet_1" : { "terms" : { "field" : "field" } } }}'

Page 39: Indices APIs - Elasticsearch Reference

Delete Warmers

$ curl -XDELETE localhost:9200/test/_warmer/warmer_1

Get Warmers

$ curl -XGET localhost:9200/test/_warmer/warmer_1$ curl -XGET localhost:9200/test/_warmer/warm*$ curl -XGET localhost:9200/test/_warmer/

Page 40: Indices APIs - Elasticsearch Reference

More GETs

Page 41: Indices APIs - Elasticsearch Reference

Status

The indices status API allows to get a comprehensive status information of one or more indices.

$ curl -XGET localhost:9200/twitter/_status$ curl -XGET localhost:9200/twitter,kimchy/_status$ curl -XGET localhost:9200/_status

Page 42: Indices APIs - Elasticsearch Reference

Stats

Indices level stats provide statistics on different operations happening on an index.

$ curl -XGET localhost:9200/twitter/_stats$ curl -XGET localhost:9200/twitter,kimchy/_stats$ curl -XGET localhost:9200/_stats

Page 43: Indices APIs - Elasticsearch Reference

Segments

Provides low level segments information that a Lucene index (shard level) is built with.

$ curl -XGET localhost:9200/twitter/_segments$ curl -XGET localhost:9200/twitter,kimchy/_segments$ curl -XGET localhost:9200/_segments

Page 44: Indices APIs - Elasticsearch Reference

Recovery

The indices recovery API provides insight into on-going shard recoveries. Recovery status may be reported for specific indices, or cluster-wide.

$ curl -XGET localhost:9200/twitter/_recovery$ curl -XGET localhost:9200/twitter,kimchy/_recovery$ curl -XGET localhost:9200/_recovery

$ curl -XGET localhost:9200/twitter/_recovery?detailed=true

Page 45: Indices APIs - Elasticsearch Reference

More POSTs

Page 46: Indices APIs - Elasticsearch Reference

Clear Cache

The clear cache API allows to clear either all caches or specific caches associated with one ore more indices.

$ curl -XPOST localhost:9200/twitter/_cache/clear$ curl -XPOST localhost:9200/twitter,kimchy/_cache/clear$ curl -XPOST localhost:9200/_cache/clear

Page 47: Indices APIs - Elasticsearch Reference

Cache Types

— filter

— field_data

— id_cache

$ curl -XPOST localhost:9200/twitter/_cache/clear?filter=true

cf. The filter cache will be cleared within 60 seconds.

Page 48: Indices APIs - Elasticsearch Reference

Flush

The flush process of an index basically frees memory from the index by flushing data to the index storage and clearing the internal transaction log.

$ curl -XPOST localhost:9200/twitter/_flush$ curl -XPOST localhost:9200/twitter,kimchy/_flush$ curl -XPOST localhost:9200/_flush

Page 49: Indices APIs - Elasticsearch Reference

Refresh

The refresh API allows to explicitly refresh one or more index, making all operations performed since the last refresh available for search.

$ curl -XPOST localhost:9200/twitter/_refresh$ curl -XPOST localhost:9200/twitter,kimchy/_refresh$ curl -XPOST localhost:9200/_refresh

Page 50: Indices APIs - Elasticsearch Reference

Optimize

The optimize process basically optimizes the index for faster search operations.

The optimize operation allows to reduce the number of segments by merging them.

$ curl -XPOST localhost:9200/twitter/_optimize$ curl -XPOST localhost:9200/twitter,kimchy/_optimize$ curl -XPOST localhost:9200/_optimize

Page 51: Indices APIs - Elasticsearch Reference

Thank You!

by Daniel Ku (http://kjunine.net)