client.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. == The Ruby Client
  2. The `elasticsearch` http://rubygems.org/gems/elasticsearch[Rubygem] provides a low-level client
  3. for communicating with an Elasticsearch cluster, fully compatible with other official clients.
  4. Full documentation is hosted at https://github.com/elastic/elasticsearch-ruby[Github]
  5. and http://rubydoc.info/gems/elasticsearch[RubyDoc]
  6. -- this documentation provides only an overview of features.
  7. === Elasticsearch Version Compatibility
  8. The Ruby API is compatible with both Elasticsearch 0.90.x and 1.0.x versions, you have to install
  9. a matching http://rubygems.org/gems/elasticsearch/versions[gem version], though:
  10. [cols="<,<",options="header",]
  11. |=========================================
  12. | Elasticsearch version | Ruby gem version
  13. | 0.90.x | 0.4.x
  14. | 1.x | 1.x
  15. |=========================================
  16. === Installation
  17. Install the Ruby gem for Elasticsearch *1.x*:
  18. [source,sh]
  19. ------------------------------------
  20. gem install elasticsearch
  21. ------------------------------------
  22. ...or add it do your Gemfile:
  23. [source,ruby]
  24. ------------------------------------
  25. gem 'elasticsearch'
  26. ------------------------------------
  27. Install the Ruby gem for Elasticsearch *0.90.x*:
  28. [source,sh]
  29. ------------------------------------
  30. gem install elasticsearch -v 0.4.10
  31. ------------------------------------
  32. ...or add it do your Gemfile:
  33. [source,ruby]
  34. ------------------------------------
  35. gem 'elasticsearch', '~> 0.4'
  36. ------------------------------------
  37. === Example Usage
  38. [source,ruby]
  39. ------------------------------------
  40. require 'elasticsearch'
  41. client = Elasticsearch::Client.new log: true
  42. client.cluster.health
  43. client.index index: 'my-index', type: 'my-document', id: 1, body: { title: 'Test' }
  44. client.indices.refresh index: 'my-index'
  45. client.search index: 'my-index', body: { query: { match: { title: 'test' } } }
  46. ------------------------------------
  47. === Features at a Glance
  48. * Pluggable logging and tracing
  49. * Pluggable connection selection strategies (round-robin, random, custom)
  50. * Pluggable transport implementation, customizable and extendable
  51. * Pluggable serializer implementation
  52. * Request retries and dead connections handling
  53. * Node reloading (based on cluster state) on errors or on demand
  54. * Modular API implementation
  55. * 100% REST API coverage
  56. === Transport and API
  57. The `elasticsearch` gem combines two separate Rubygems:
  58. * https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport[`elasticsearch-transport`]
  59. provides a HTTP Ruby client for connecting to the Elasticsearch cluster,
  60. * https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-api[`elasticsearch-api`]
  61. provides a Ruby API for the Elasticsearch RESTful API.
  62. Please see their respective documentation for configuration options and technical details.
  63. Notably, the documentation and comprehensive examples for all the API methods is contained in the source,
  64. and available online at http://rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Actions[Rubydoc].
  65. Keep in mind, that for optimal performance, you should use a HTTP library which supports
  66. persistent ("keep-alive") HTTP connections.
  67. === Extensions
  68. The https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-extensions[`elasticsearch-extensions`]
  69. Rubygem provides a number of extensions to the core client, such as an API to programatically launch
  70. Elasticsearch clusters (eg. for testing purposes), and more.
  71. Please see its
  72. https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-extensions[documentation]
  73. for more information.