Download - Elasticsearch 101

Transcript
Page 1: Elasticsearch 101

(the VERY basics of it)

Page 2: Elasticsearch 101
Page 3: Elasticsearch 101

Elasticsearch is a highly scalable open-source full-text search and analytics engine.

Page 4: Elasticsearch 101

● A cluster is a collection of one or more nodes (servers) that together holds your entire data and provides federated indexing and search capabilities across all nodes.

● A node is a single server that is part of your cluster, stores your data, and participates in the cluster’s indexing and search capabilities.

● An index is a collection of documents that have somewhat similar characteristics.

● A document is a basic unit of information that can be indexed.

● A type is a logical category/partition of your index whose semantics is completely up to you.

cluster

node

index

type

type

document

document

document

document

Page 5: Elasticsearch 101

● Elasticsearch provides the ability to subdivide your index into multiple pieces called shards.

clusternode

Index: shard 1type

document

document

Index: shard 2type

document

document

Page 6: Elasticsearch 101
Page 7: Elasticsearch 101

● Elasticsearch allows you to make one or more copies of your index’s shards into what are called replica shards, or replicas for short.

clusternode

Index: shard 1type

document

document

Index: shard 2type

document

document

Index: shard 1: replicatype

document

document

Index: shard 2: replicatype

document

document

Page 8: Elasticsearch 101
Page 9: Elasticsearch 101

installation

● Java

● http://www.elasticsearch.org/download/

Page 10: Elasticsearch 101

http://localhost:9200/{

"ok": true,

"status": 200,

"name": "Red Lotus",

"version": {

"number": "0.90.13",

"build_hash": "249c9c5e06765c9e929e92b1d235e1ba4dc679fa",

"build_timestamp": "2014-03-25T15:27:12Z",

"build_snapshot": false,

"lucene_version": "4.6"

},

"tagline": "You Know, for Search"

}

Page 11: Elasticsearch 101

http://localhost:9200/_plugin/head/

Page 12: Elasticsearch 101

Create an index named 'movies_1.0.0'

curl ­XPUT 'http://localhost:9200/movies_1.0.0'

Page 13: Elasticsearch 101

a concise list of all indices and their aliases in your cluster

curl http://localhost:9200/_aliases

Page 14: Elasticsearch 101

Add an index alias

curl ­XPOST 'http://localhost:9200/_aliases' ­d '

{

    "actions" : [

        {

           "add" : {

              "index" : "movies_1.0.0", 

              "alias" : "movies" 

           } 

        }

    ]

}'

Page 15: Elasticsearch 101

Create a type called 'movie'curl -XPUT 'http://localhost:9200/movies/movie/_mapping' -d '{

"movie":{

"properties":{

"director":{

"type":"string"

},

"genres":{

"type":"string"

},

"title":{

"type":"string"

},

"year":{

"type":"long"

}

}

}

}'

Page 16: Elasticsearch 101

get mapping of a type

curl ­XGET 'http://localhost:9200/movies/movie/_mapping'

Page 17: Elasticsearch 101

Create a document

curl ­XPUT "http://localhost:9200/movies/movie/1" ­d'

{

    "title": "The Godfather",

    "director": "Francis Ford Coppola",

    "year": 1972,

    "genres": ["Adventure"]

}'

Page 18: Elasticsearch 101

Retrieve the document

curl ­XGET "http://localhost:9200/movies/movie/1" 

Page 19: Elasticsearch 101

more data...curl ­XPUT "http://localhost:9200/movies/movie/1" ­d'

{

    "title": "The Godfather",

    "director": "Francis Ford Coppola",

    "year": 1972,

    "genres": ["Crime", "Drama"]

}'

curl ­XPUT "http://localhost:9200/movies/movie/2" ­d'

{

    "title": "Lawrence of Arabia",

    "director": "David Lean",

    "year": 1962,

    "genres": ["Adventure", "Biography", "Drama"]

}'

curl ­XPUT "http://localhost:9200/movies/movie/3" ­d'

{

    "title": "To Kill a Mockingbird",

    "director": "Robert Mulligan",

    "year": 1962,

    "genres": ["Crime", "Drama", "Mystery"]

}'

curl ­XPUT "http://localhost:9200/movies/movie/4" ­d'

{

    "title": "Apocalypse Now",

    "director": "Francis Ford Coppola",

    "year": 1979,

    "genres": ["Drama", "War"]

}'

curl ­XPUT "http://localhost:9200/movies/movie/5" ­d'

{

    "title": "Kill Bill: Vol. 1",

    "director": "Quentin Tarantino",

    "year": 2003,

    "genres": ["Action", "Crime", "Thriller"]

}'

curl ­XPUT "http://localhost:9200/movies/movie/6" ­d'

{

    "title": "The Assassination of Jesse James by the Coward Robert Ford",

    "director": "Andrew Dominik",

    "year": 2007,

    "genres": ["Biography", "Crime", "Drama"]

}'

Page 20: Elasticsearch 101

Querying

Page 21: Elasticsearch 101

Show all

 curl ­XGET 'http://localhost:9200/movies/_search' ­d '{

    "query": {

        "match_all": {}

    }

}'

Page 22: Elasticsearch 101

Search request bodycurl ­XPOST "http://localhost:9200/_search" ­d'

{

    "query": {

        "query_string": {

            "query": "kill"         

        }

    }

}'

Page 23: Elasticsearch 101
Page 24: Elasticsearch 101

Specifying fields to search in

curl ­XPOST "http://localhost:9200/_search" ­d'

{

    "query": {

        "query_string": {

            "query": "ford",

            "fields": ["title"]

        }

    }

}'

Page 25: Elasticsearch 101

Filtering

Page 26: Elasticsearch 101

Filtering sample 1curl ­XPOST "http://localhost:9200/_search" ­d'

{

    "query": {

        "filtered": {

            "query": {

                "match_all": {

                }

            },

            "filter": {

                "term": { "year": 1962 }

            }

        }

    }

}'

Page 27: Elasticsearch 101

Filtering sample 2curl ­XPOST "http://localhost:9200/_search" ­d'

{

    "query": {

        "filtered": {

            "query": {

                "query_string": {

                    "query": "drama"

                }

            },

            "filter": {

                "term": { "year": 1962 }

            }

        }

    }

}'

Page 28: Elasticsearch 101

references

http://joelabrahamsson.com/elasticsearch­101/

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_basic_concepts.

html


Top Related