Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Introduction to Elasticsearch

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio

Eche un vistazo a continuación

1 de 62 Anuncio

Introduction to Elasticsearch

Descargar para leer sin conexión

An Introductory talk about Elasticsearch I gave on MaceioDEVMeetup #5.

Event: http://www.meetup.com/maceio-dev-meetup/events/220830067/

An Introductory talk about Elasticsearch I gave on MaceioDEVMeetup #5.

Event: http://www.meetup.com/maceio-dev-meetup/events/220830067/

Anuncio
Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

A los espectadores también les gustó (20)

Anuncio

Similares a Introduction to Elasticsearch (20)

Anuncio

Más reciente (20)

Introduction to Elasticsearch

  1. 1. Elasticsearch Tony Messias MaceioDevMeetup #5
  2. 2. who am I? ➔ Tony Messias ~ @tony0x01 ➔ Building web stuff since ~2010
  3. 3. search
  4. 4. what is “search”? “A search is the organized pursuit of information (...) that you want to find, but you have no idea where it is.” (NASA).
  5. 5. how do we add search to our apps? ➔ SQL queries (not just LIKE queries); ➔ Elasticsearch; ➔ Lucene; ➔ Solr; ➔ …
  6. 6. how do we add search to our apps? ➔ SQL queries (not just LIKE queries); ➔ Elasticsearch; ➔ Lucene; ➔ Solr; ➔ …
  7. 7. who uses it?
  8. 8. what is Elasticsearch? ➔ database server; ➔ document based; ➔ based on Apache Lucene; ➔ schema-free*;
  9. 9. why Elasticsearch? ➔ speaks HTTP/JSON; ➔ easy to setup; ➔ data replication; ➔ easily scalable;
  10. 10. what can I use it for?
  11. 11. but it can do more than that…
  12. 12. some analogy * Relational ES database index table type row document column field schema mapping index everything SQL QueryDSL
  13. 13. REST(ish) $ curl -XPOST http://es-server.com/index/type/id -d '{}'
  14. 14. REST(ish) $ curl -XPOST http://es-server.com/index/type/id -d '{}'
  15. 15. REST(ish) $ curl -XPOST http://es-server.com/index/type/id -d '{}'
  16. 16. REST(ish) $ curl -XPOST http://es-server.com/index/type/id -d '{}'
  17. 17. REST(ish) $ curl -XPOST http://es-server.com/index/type/id -d '{}'
  18. 18. enough with the talking… let’s do some searches!
  19. 19. but first, let’s talk about CRUD
  20. 20. indexing
  21. 21. { "email": "john@smith.com", "first_name": "John", "last_name": "Smith", "info": { "bio": "Eco-warrior and defender of the weak", "age": 25, "interests": [ "dolphins", "whales" ] }, "join_date": "2014/05/01" }
  22. 22. $ curl -XPOST localhost:9200/my-app/users -d ‘{ "email": "john@smith.com", "first_name": "John", "last_name": "Smith", "info": { "bio": "Eco-warrior and defender of the weak", "age": 25, "interests": [ "dolphins", "whales" ] }, "join_date": "2014/05/01" }’
  23. 23. { "_index": "my-app", "_type": "users", "_id": "AUxOBeJbue-jeR3jNcHj", "_version": 1, "created": true }
  24. 24. $ curl -XPUT localhost:9200/my-app/users/AUxOBeJbue-jeR3jNcHj -d ‘{ "email": "john@smith.com", "first_name": "John" }’
  25. 25. { "_index": "my-app", "_type": "users", "_id": "AUxOBeJbue-jeR3jNcHj", "_version": 2, "created": false }
  26. 26. $ curl -XGET localhost:9200/my-app/users/AUxOBeJbue-jeR3jNcHj { "_index": "my-app", "_type": "users", "_id": "AUxOJe-4ue-jeR3jNcHo", "_version": 2, "found": true, "_source": { "email": "john@smith.com", "first_name": "John" } }
  27. 27. $ curl -XDELETE localhost:9200/my-app/users/AUxOBeJbue-jeR3jNcHj { "found": true, "_index": "my-app", "_type": "users", "_id": "AUxOBeJbue-jeR3jNcHj", "_version": 3 }
  28. 28. searching
  29. 29. $ curl -XPOST localhost:9200/my-app/users/_search -d ‘{ "query": { "match": { "first_name": "John" } } }’
  30. 30. { ..., "hits": { "total": 4, "max_score": 0.30685282, "hits": [ { "_index": "my-app", "_type": "users", "_id": "AUxOJWlCue-jeR3jNcHn", "_score": 0.30685282, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Doe", "info": { "bio": "Like rock music", "age": 35, "interests": [ "dolphins", "whales" ] }, "join_date": "2014/05/01" } },...
  31. 31. $ curl -XPOST localhost:9200/my-app/users/_search -d ‘{ "query": { "filtered": { "query": { "match": { "first_name": "John" } }, "filter": { "range": { "info.age": { "gt": 34 } } } } } }’
  32. 32. { "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.30685282, "hits": [ { "_index": "my-app", "_type": "users", "_id": "AUxOJWlCue-jeR3jNcHn", "_score": 0.30685282, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Doe", "info": { "bio": "Like rock music", "age": 35, "interests": ["dolphins","whales"] }, "join_date": "2014/05/01" } } ] } }
  33. 33. queries vs. filters
  34. 34. queries vs. filters
  35. 35. full-text search
  36. 36. $ curl -XPOST localhost:9200/my-app/users/_search -d ‘{ "query": { "match": { "info.bio": "rock climbing" } } }’
  37. 37. { "took": 9, "timed_out": false, "_shards": {...}, "hits": { "total": 2, "max_score": 0.2169777, "hits": [ { "_index": "my-app", "_type": "users", "_id": "AUxOJe-4ue-jeR3jNcHo", "_score": 0.2169777, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Kennedy", "info": { "bio": "I love rock climbing!", "age": 29, "interests": ["dolphins","whales"] }, "join_date": "2014/05/01" } }, { "_index": "my-app", "_type": "users", "_id": "AUxOJWlCue-jeR3jNcHn", "_score": 0.02250402, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Doe", "info": { "bio": "Like rock music", "age": 35, "interests": ["dolphins","whales"] }, "join_date": "2014/05/01" } } ] } }
  38. 38. $ curl -XPOST localhost:9200/my-app/users/_search -d ‘{ "query": { "match_phrase": { "info.bio": "rock climbing" } } }’
  39. 39. {…, "hits": { "total": 1, "max_score": 0.30685282, "hits": [ { "_index": "my-app", "_type": "users", "_id": "AUxOJe-4ue-jeR3jNcHo", "_score": 0.30685282, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Kennedy", "info": { "bio": "I love rock climbing!", "age": 29, "interests": ["dolphins","whales"] }, "join_date": "2014/05/01" } } ] } }
  40. 40. $ curl -XPOST localhost:9200/my-app/users/_search -d ‘{ "query": { "match_phrase": { "info.bio": "rock climbing" } }, "highlight": { "fields": { "info.bio": {} } } }’
  41. 41. ... { "_index": "my-app", "_type": "users", "_id": "AUxOJe-4ue-jeR3jNcHo", "_score": 0.30685282, "_source": { "email": "john@smith.com", "first_name": "John", "last_name": "Kennedy", "info": { "bio": "I love rock climbing!", "age": 29, "interests": ["dolphins","whales"] }, "join_date": "2014/05/01" }, "highlight": { "info.bio": ["I love <em>rock</em> <em>climbing</em>!"] } } ] } }
  42. 42. is this it?
  43. 43. analytics
  44. 44. aggregations
  45. 45. buckets metrics
  46. 46. $ curl -XPOST localhost:9200/my-app/users/_search?search_type=count -d'{ "aggs": { "all_interests": { "terms": { "field": "info.interests" } } } }'
  47. 47. { ..., "hits": {"total": 4,"max_score": 0,"hits": []}, "aggregations": { "all_interests": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "whales", "doc_count": 4 }, { "key": "dolphins", "doc_count": 3 } ] } }}
  48. 48. $ curl -XPOST localhost:9200/my-app/users/_search?search_type=count -d'{ "aggs": { "all_interests": { "terms": { "field": "info.interests" } } } }'
  49. 49. $ curl -XPOST localhost:9200/my-app/users/_search?search_type=count -d'{ "aggs": { "all_interests": { "terms": { "field": "info.interests" }, "aggs": { "avg_age": { "avg": { "field": "info.age" } } } } } }'
  50. 50. { …, "aggregations": { "all_interests": { …, "buckets": [ { "key": "whales", "doc_count": 4, "avg_age": { "value": 31.5 } }, { "key": "dolphins", "doc_count": 3, "avg_age": { "value": 32.333333333333336 } } ] }}}
  51. 51. $ curl -XPOST localhost:9200/my-app/users/_search?search_type=count -d'{ "query": { "match_phrase": { "info.bio": "rock climbing" } }, "aggs": { "all_interests": { "terms": { "field": "info.interests" }, "aggs": { "avg_age": { "avg": { "field": "info.age" } } } } }}'
  52. 52. { …, "aggregations": { "all_interests": { …, "buckets": [ { "key": "whales", "doc_count": 1, "avg_age": { "value": 29 } } ] }}}
  53. 53. questions?
  54. 54. Resources ➔ http://www.elastic. co/guide/en/elasticsearch/guide/current/index. html ➔ https://leanpub.com/elasticsearch-quick-start ➔ https://www.elastic.co/use-cases ➔ https://speakerdeck.com/asm89/elasticsearch
  55. 55. Resources ➔ https://speakerdeck. com/johnbeynon/elasticsearch-101 ➔ http://blog.madewithlove.be/post/integrating- elasticsearch-with-your-laravel-app/ ➔ http://blog.madewithlove.be/post/elasticsearch- aggregations/

×