Class: ElasticSearch::IndexRequest
- Defined in:
- lib/jruby-elasticsearch/indexrequest.rb
Instance Method Summary collapse
-
#execute(&block) ⇒ Object
Execute this index request.
-
#execute! ⇒ Object
Execute this index request synchronously.
-
#initialize(client, index, type, id = nil, data = {}) ⇒ IndexRequest
constructor
Create a new index request.
-
#method_missing(*args) ⇒ Object
DSL helper.
Methods inherited from Request
Constructor Details
#initialize(client, index, type, id = nil, data = {}) ⇒ IndexRequest
Create a new index request.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jruby-elasticsearch/indexrequest.rb', line 6 def initialize(client, index, type, id=nil, data={}) @client = client @index = index @type = type @id = id @data = data # This should silence jruby warnings for 'multiple java methods for prepareIndex' if id.nil? @prep = @client.prepareIndex(index, type) else @prep = @client.prepareIndex(index, type, id) end super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
DSL helper. TODO(sissel): Move this away to a DSL module.
42 43 44 45 46 |
# File 'lib/jruby-elasticsearch/indexrequest.rb', line 42 def method_missing(*args) key, value = args puts "Adding: #{key}: #{value.inspect}" @data[key.to_s] = value end |
Instance Method Details
#execute(&block) ⇒ Object
Execute this index request. This call is asynchronous.
If a block is given, register it for both failure and success.
26 27 28 29 30 31 32 |
# File 'lib/jruby-elasticsearch/indexrequest.rb', line 26 def execute(&block) @prep.setSource(@data) use_callback(&block) if block_given? action = @prep.execute(@handler) return action end |
#execute! ⇒ Object
Execute this index request synchronously
35 36 37 38 |
# File 'lib/jruby-elasticsearch/indexrequest.rb', line 35 def execute! @prep.setSource(@data) return @prep.execute.actionGet() end |