Slide 1

Slide 1 text

Elasticsearch i Symfony, FOSElasticaBundle DaFED, Novi Sad, 06/06/ 2015

Slide 2

Slide 2 text

Miloš Milojević Master’s Degree in Communication and Information Technology. Web developer in Eton Digital. Loves open source. Interested in database architecture and optimisation.

Slide 3

Slide 3 text

Introduction to Elasticsearch

Slide 4

Slide 4 text

https://www.elastic.co/downloads/elasticsearch

Slide 5

Slide 5 text

:~$ cd elasticsearch :~$ bin/elasticsearch Elasticsearch started….

Slide 6

Slide 6 text

curl -XGET ‘http://localhost:9200’ { "status" : 200, "name" : "Tutinax the Mountain-Mover", "cluster_name" : "elasticsearch", "version" : { "number" : "1.5.2", "build_hash" : "62ff9868b4c8a0c45860bebb259e21980778ab1c", "build_timestamp" : "2015-04-27T09:21:06Z", "build_snapshot" : false, "lucene_version" : "4.10.4" }, "tagline" : "You Know, for Search" }

Slide 7

Slide 7 text

010011 100100 110110 001001 Restful API { } { “Hello” : “World” }

Slide 8

Slide 8 text

-Cluster cluster.name = elasticsearch -Nodes: -Allow this node to be eligible as a master node (enabled by default): #node.master: true -Allow this node to store data (enabled by default): #node.data: true

Slide 9

Slide 9 text

You can exploit these settings to design advanced cluster topologies. Node example: 1. You want this node to never become a master node, only to hold data. This will be the "workhorse" of your cluster. node.master: false node.data: true

Slide 10

Slide 10 text

Node example: 2. You want this node to only serve as a master: to not store any data and to have free resources. This will be the "coordinator" of your cluster. node.master: true node.data: false

Slide 11

Slide 11 text

Node example: 3. You want this node to be neither master nor data node, but to act as a "search load balancer" (fetching data from nodes,aggregating results, etc.) node.master: false node.data: false

Slide 12

Slide 12 text

Node 1

Slide 13

Slide 13 text

Node 1 Node 2

Slide 14

Slide 14 text

Node 1 Node 2

Slide 15

Slide 15 text

Node 1 Node 2 Node 3

Slide 16

Slide 16 text

Node 1 Node 2 Node 3

Slide 17

Slide 17 text

Node 1 Node 2 Node 3

Slide 18

Slide 18 text

Node 1 Node 2

Slide 19

Slide 19 text

Node 1 Node 2

Slide 20

Slide 20 text

{ “ok” : true, “_index” : “milos”, “_type” : “post”, “_id” : “1”, “_version” : 1 } milos milos_sec milos

Slide 21

Slide 21 text

{ “ok” : true, “_index” : “milos”, “_type” : “post”, “_id” : “1”, “_version” : 1 } milos post user

Slide 22

Slide 22 text

{ “ok” : true, “_index” : “milos”, “_type” : “post”, “_id” : “1”, “_version” : 1 } milos post 1 2 3

Slide 23

Slide 23 text

Add document: curl -XPUT “http:localhost:9200/milos/post/1” -d “{‘title’ : ‘Introduction to elasticsearch’}” {"_index":"milos","_type":"post","_id":"1","_version":1,"created":true} Index type id

Slide 24

Slide 24 text

Update: curl -XPOST “http:localhost:9200/milos/post/1” -d “{ ‘title’ : ‘Introduction to elasticsearch’, ‘tags’ : [‘elasticsearch’,‘php’] }” {"_index":"milos","_type":"post","_id":"1","_version":2,"created":false}

Slide 25

Slide 25 text

Delete document: curl -XDELETE “http:localhost:9200/milos/post/1” {"found":true,"_index":"milos","_type":"post","_id":"1","_version":3}

Slide 26

Slide 26 text

Delete type: curl -XDELETE “http:localhost:9200/milos/post” {"acknowledged":true}

Slide 27

Slide 27 text

Delete index: curl -XDELETE “http:localhost:9200/milos” {"acknowledged":true}

Slide 28

Slide 28 text

curl -XGET “http://localhost:9200/milos/_search?q=Introduction”

Slide 29

Slide 29 text

curl -XGET “http://localhost:9200/milos/_search?q=Introduction” { "took":83, "timed_out":false, "_shards": { "total":5, "successful":5, "failed":0 },

Slide 30

Slide 30 text

"hits": { "total":1, "max_score":0.13424811, "hits": [{ "_index":"milos", "_type":"post", "_id":"1", "_score":0.13424811, "_source": { "title" : "Introduction to elasticsearch", "tags": ["elasticsearch", "php"] } }] } }

Slide 31

Slide 31 text

curl -XPOST “http://localhost:9200/milos/_search” -d ‘{“query”:{“terms”:{“tags”: [“php”,”elasticsearch”] }}}’

Slide 32

Slide 32 text

curl -XPOST “http://localhost:9200/milos/_search” -d ‘{“query”:{“terms”:{“tags”: [“php”,”elasticsearch”] }}}’ { "took":43, "timed_out":false, "_shards": { "total":5, "successful":5, "failed":0 },

Slide 33

Slide 33 text

{ "_index":"milos", "_type":"post", "_id":"1", "_score":0.2712221, "_source": { "title" : "Introduction to elasticsearch", "tags": ["elasticsearch", "php"] } }, { "_index":"milos", "_type":"post", "_id":"2", "_score":0.2712221, "_source": { "title" : "Introduction to elasticsearch number 2", "tags": ["elasticsearch", "php"] } }

Slide 34

Slide 34 text

curl -XPUT “http://localhost:9200/milos” -d ‘ { “settings” : { “number_of_shards” : 10, “number_of_replicas” : 3 }, { “mappings” : { “document” : { “properties” : {“title” : { “type” : string, “analyzer” : “lowercase” }} }}’

Slide 35

Slide 35 text

MySql Elasticsearch Database Index Table Type Row Document Column Field Schema Mapping Index Everything is indexed Sql Query DSL Select * from table…. GET http://…. Update table SET ... POST http://…. Terminology

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

FOSElasticaBundle https://github.com/FriendsOfSymfony/FOSElasticaBundle

Slide 38

Slide 38 text

composer require friendsofsymfony/elastica-bundle new FOS\ElasticaBundle\FOSElasticaBundle() app/config/config.yml fos_elastica: clients: default: %elastica_client% indexes: index_name: settings: index: …. php app/console fos:elastica:populate

Slide 39

Slide 39 text

…..

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

….

Slide 42

Slide 42 text

What about boost???

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Thank you. facebook.com/milosmoto linkedin.com/in/milosmoto @milosmoto