Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Elasticsearch - Zero to Hero

A hands on training about Elasticsearch I gave at TechFinancials IL

  • Login to see the comments

Elasticsearch - Zero to Hero

  1. 1. Elasticsearch From Zero to Hero Daniel Ziv
  2. 2. Whatiselasticsearch? ElasticSearch is a text-search software created by Shay Banon (An Israeli guy!). Under the hood it uses Lucene for it’s fest and intelligent text abilities.
  3. 3. Itchangedalotovertheyears!
  4. 4. Andcollectedmanyfriendsalongtheway
  5. 5. Keyfeatures Elasticsearch has a lot to offer, here’s just some of the stuff: ● RESTful API for querying and inserting data ● Massive aggregations abilities ● Custom and pre-made “analyzers” / ”tokenizers” ● It’s easy to scale and cluster ● “Discovery” and “Transport” ● It uses “Sharding” and “Voting” for better performance
  6. 6. architecture Only masters get to “Vote” (and hold data). Data nodes are just keeping your data safe. Load balancers are nodes that holds no data and don’t get to vote. So… How many “Masters” do I need? OUR PORTS: 9200-9299 for HTTP Access 9300-9400 for Discovery & Transport Protocol
  7. 7. Replicaaass!!
  8. 8. Thecrud! C - Create R - Retrieve U - Update D - Delete * CURD
  9. 9. FromIndexestodocuments Indexes are like databases, each index holds multiple types (tables) and each type define the documents in it (records). A document is the JSON implementation of each entity, and has many fields with different attributes.
  10. 10. Itlookssomethinglikethis
  11. 11. Let’srecap
  12. 12. Handson!
  13. 13. Installing ● Java 7 is strongly preferred over Java 6. Either Oracle or OpenJDK are acceptable. ● Download and Install ● Run curl -X GET http://localhost:9200 (Or browse with Chrome) ● Add this collection to your Postman
  14. 14. Createindexes Create a new index for “posts”: curl -XPUT 'localhost:9200/my_index’ { "acknowledged" : true } Try to create it again and it throws exception.
  15. 15. Indexes“metadata” From now on, we call it “Mapping” (oohhh… fancy!) Each index has one or more mapping types, which are used to divide the documents in an index into logical groups. User documents might be stored in a user type, and blog posts in a blogpost type. So Let’s create an Index with Mapping (postman)
  16. 16. Workingwithdocuments Now open your postman and: 1.Create your first tweet 2.Create a formatted tweet 3.Update your tweet 4.Request a specific version 5.Delete your tweet 6.Delete your Index
  17. 17. Querying Download and run some test data To query Elasticsearch we use QueryDSL, and we send the query JSON to the server via POST method. QueryDSL is consisting of two types of clauses: 1. Leaf query clauses: looks for a particular value in a particular field (Match/Term/Range) 2. Compound query clauses: Compound query clauses wrap other leaf or compound queries
  18. 18. Leafqueries
  19. 19. SELECT*FROMTWEETS { "query": { "match_all": {} } }
  20. 20. Where { "query": { "match" : { "title" : "hi" } } } Advanced
  21. 21. Where { "query": { "multi_match" : { "query": "hi", "fields": [ "subject", "title" ] } } }
  22. 22. Range { "query": { "range" : { "likes" : { "gte" : 1, "lte" : 20 } } } } gte Greater-than or equal to gt Greater-than lte Less-than or equal to lt Less-than
  23. 23. Exists { "query": { "exists" : { "field" : "title" } } } (And “missing” is the opposite operation)
  24. 24. PREFIX { "query": { "prefix" : { "title" : "h" } } }
  25. 25. Compoundqueries
  26. 26. BinaryOperators -AND { "query" : { "filtered" : { "query" : { "match" : { "title" : "Hi" } }, "filter" : { "and" : [ { "range" : { "likes" : { "gte" : 10, "lte" : 20 } } } ] } } } }
  27. 27. BinaryOperators -or { "query" : { "filtered" : { "query" : { "match" : { "title" : "Hi" } }, "filter" : { "or" : [ { "range" : { "likes" : { "lte" : 20 } } } , { "match" : { "likes" : "25" } } ] } } } }
  28. 28. BinaryOperators -not { "query" : { "bool" : { "must" : { "match" : { "title" : "Hi" } }, "filter" : { "not" : { "range" : { "likes" : { "gte" : 10, "lte" : 20 } } } } } } }
  29. 29. Limit(pershard) { "query" : { "filtered" : { "filter" : { "limit" : {"value" : 2} }, "query" : { "match_all": {} } } } }
  30. 30. AdvancedClass
  31. 31. Advancedqueries ● Joining queries ● Geo queries ● Specialized queries ● Span queries
  32. 32. Advancedtopics ● Heap Sizing - DevOps Must ● Elasticsearch and NginX ● Transport Protocol ● Elasticsearch Head ● Plugins and Analyzers ● Aggregations Docs - Dev & PM Must ● Bulk API - Dev Must
  33. 33. Thankyou!

×