module Elastictastic
Autogenerated by Thrift
Compiler (0.8.0-dev)
DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
Constants
- CancelSave
- Error
- IllegalModificationError
- MissingParameter
- NestedDocument
- NoServerAvailable
- Observer
- OperationNotAllowed
- RecordInvalid
- VERSION
Attributes
Public Class Methods
Coerce the argument to an Elastictastic
index.
@param [String,Elastictastic::Index] name_or_index Index
name or object @api private
# File lib/elastictastic.rb, line 197 def Index(name_or_index) Index === name_or_index ? name_or_index : Index.new(name_or_index) end
Perform write operations in a single request to ElasticSearch. Highly recommended for any operation which writes a large quantity of data to ElasticSearch. Write operations (e.g. save/destroy documents) are buffered in the client and sent to ElasticSearch when the bulk operation exits (or when an auto-flush threshold is reached; see below).
@example Create posts in bulk
Elastictastic.bulk do params[:posts].each do |post_params| Post.new(post_params).save! end end # posts are actually persisted here
Since write operations inside a bulk block are not performed synchronously, server-side errors will only be raised once the bulk block completes; you may pass a block into Document#save
and Document#destroy
that will be called once the operation completes. The block is passed an error param if the operation was not successful.
@example Custom handling for conflicting IDs in a bulk block
errors = [] Elastictastic.bulk do params[:posts].each do |post_params| Post.new(post_params).save! do |e| case e when nil # success! when Elastictastic::ServerError::DocumentAlreadyExistsEngineException conflicting_ids << post_params[:id] else raise e end end end end
@option options [Fixnum] :auto_flush Flush to ElasticSearch after this many operations performed. @yield Block during which all write operations are buffered for bulk
# File lib/elastictastic.rb, line 149 def bulk(options = {}) original_persister = self.persister bulk_persister = self.persister = Elastictastic::BulkPersistenceStrategy.new(options) begin yield ensure self.persister = original_persister end bulk_persister.flush end
Return a lower-level ElasticSearch client. This is likely to be extracted into a separate gem in the future.
@return [Client] client @api private
# File lib/elastictastic.rb, line 81 def client Thread.current['Elastictastic::client'] ||= Client.new(config) end
Elastictastic
global configuration. In a Rails environment, you can configure Elastictastic
by creating a ‘config/elastictastic.yml` file, whose keys will be passed into the Configuration
object when your application boots. In non-Rails environment, you can configure Elastictastic
directly using the object returned by this method.
@return [Configuration] global configuration object
# File lib/elastictastic.rb, line 57 def config @config ||= Configuration.new end
Use Elastictastic’s configured JSON decoder to decode a JSON message
@param [String] JSON message to decode @return Ruby object represented by json param @api private
# File lib/elastictastic.rb, line 183 def json_decode(json) if config.json_engine.respond_to?(:decode) config.json_engine.decode(json) else config.json_engine.load(json) end end
Use Elastictastic’s configured JSON encoder to encode a JSON message.
@param [Object] Object to encode to JSON @return JSON representation of object @api private
# File lib/elastictastic.rb, line 168 def json_encode(object) if config.json_engine.respond_to?(:encode) config.json_engine.encode(object) else config.json_engine.dump(object) end end
# File lib/elastictastic.rb, line 61 def multi_get(&block) MultiGet.new.tap(&block).to_a end
Perform multiple searches in a single request to ElasticSearch. Each scope will be eagerly populated with results.
@param [Scope, Array] collection of scopes to execute multisearch on
# File lib/elastictastic.rb, line 71 def multi_search(*scopes) end
The current persistence strategy for ElasticSearch. Usually this will be the DiscretePersistenceStrategy
singleton; inside a ::bulk
block, it will be an instance of BulkPersistenceStrategy
@return [DiscretePersistenceStrategy,BulkPersistenceStrategy] current persistence strategy @api private @see ::bulk
# File lib/elastictastic.rb, line 105 def persister Thread.current['Elastictastic::persister'] ||= Elastictastic::DiscretePersistenceStrategy.instance end
Set the current persistence strategy
@param [DiscretePersistenceStrategy,BulkPersistenceStrategy] persistence strategy @api private @see ::persister
# File lib/elastictastic.rb, line 92 def persister=(persister) Thread.current['Elastictastic::persister'] = persister end