Class: EsTractor::Client
- Inherits:
-
Object
- Object
- EsTractor::Client
- Defined in:
- lib/es_tractor/client.rb
Overview
Client provides an Elasticsearch::Client with a limited subset of methods and simplified arguments.
Constant Summary collapse
- ELASTICSEARCH_INDEX =
ENV['ES_TRACTOR_ELASTICSEARCH_INDEX']
- ELASTICSEARCH_HOST =
ENV['ES_TRACTOR_ELASTICSEARCH_HOST']
Instance Attribute Summary collapse
- #client ⇒ Object readonly
Instance Method Summary collapse
-
#count(opts = {}) ⇒ Hash
Count documents, filtered by options.
-
#initialize(log = false) ⇒ Client
constructor
A new instance of Client.
-
#search(opts) ⇒ Hash
Search documents, filtered by options, aggregate on special aggregations keys.
Constructor Details
#initialize(log = false) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 |
# File 'lib/es_tractor/client.rb', line 22 def initialize(log = false) @client = Elasticsearch::Client.new( host: ELASTICSEARCH_HOST, log: log, ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
19 20 21 |
# File 'lib/es_tractor/client.rb', line 19 def client @client end |
Instance Method Details
#count(opts = {}) ⇒ Hash
Count documents, filtered by options.
71 72 73 74 |
# File 'lib/es_tractor/client.rb', line 71 def count(opts = {}) args = { body: body(opts) } @client.count(args) end |
#search(opts) ⇒ Hash
Search documents, filtered by options, aggregate on special aggregations keys.
Supported aggregations (avg, cardinality, extended_stats, geo_bounds, geo_centroid, max min, percentiles, stats, sum, value_count) take a field name and are automatically named.
146 147 148 149 150 151 152 153 |
# File 'lib/es_tractor/client.rb', line 146 def search(opts) args = { from: opts[:from] ? opts[:from] : 0, size: opts[:size] ? opts[:size] : 0, body: body(opts), } @client.search(args) end |