client.asciidoc 3.5 KB

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