Class: JayAPI::Elasticsearch::Index
- Inherits:
-
Object
- Object
- JayAPI::Elasticsearch::Index
- Includes:
- Indexable
- Defined in:
- lib/jay_api/elasticsearch/index.rb
Overview
Represents an Elasticsearch index. Allows data to be pushed to it one record at a time or in batches of the specified size.
Constant Summary
Constants included from Indexable
JayAPI::Elasticsearch::Indexable::DEFAULT_DOC_TYPE, JayAPI::Elasticsearch::Indexable::SUPPORTED_TYPES
Instance Attribute Summary
Attributes included from Indexable
Instance Method Summary collapse
-
#force_merge(only_expunge_deletes: nil) ⇒ Hash
Starts a Forced Segment Merge process on the index.
-
#index(data, type: DEFAULT_DOC_TYPE) ⇒ Hash
Sends a record to the Elasticsearch instance right away.
-
#index_name ⇒ String
The name of the Elasticsearch index.
-
#initialize(client:, index_name:, batch_size: 100, logger: nil) ⇒ Index
constructor
A new instance of Index.
-
#settings ⇒ JayAPI::Elasticsearch::Indices::Settings
The settings for the index.
Methods included from Indexable
#delete_by_query, #delete_by_query_async, #flush, #push, #queue_size, #search
Constructor Details
#initialize(client:, index_name:, batch_size: 100, logger: nil) ⇒ Index
Returns a new instance of Index.
21 22 23 |
# File 'lib/jay_api/elasticsearch/index.rb', line 21 def initialize(client:, index_name:, batch_size: 100, logger: nil) super(client: client, index_names: [index_name], batch_size: batch_size, logger: logger) end |
Instance Method Details
#force_merge(only_expunge_deletes: nil) ⇒ Hash
Starts a Forced Segment Merge process on the index.
⚠️ For big indexes this process can take a very long time, make sure to
adjust the timeout when creating the client.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jay_api/elasticsearch/index.rb', line 74 def force_merge(only_expunge_deletes: nil) unless settings.blocks.write_blocked? raise ::JayAPI::Elasticsearch::Errors::WritableIndexError, "Write block for '#{index_name}' has not been enabled. " \ "Please enable the index's write block before performing a segment merge" end params = { index: index_name, only_expunge_deletes: }.compact client.transport_client.indices.forcemerge(**params) end |
#index(data, type: DEFAULT_DOC_TYPE) ⇒ Hash
Sends a record to the Elasticsearch instance right away.
{
"_index" => "xyz01_unit_test",
"_type" => "nested",
"_id" => "SVY1mJEBQ5CNFZM8Lodt",
"_version" => 1,
"result" => "created",
"_shards" => { "total" => 2, "successful" => 1, "failed" => 0 },
"_seq_no" => 0,
"_primary_term" => 1
}
For information on the contents of this Hash please see: www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#docs-index-api-response-body
51 52 53 |
# File 'lib/jay_api/elasticsearch/index.rb', line 51 def index(data, type: DEFAULT_DOC_TYPE) super.first end |
#index_name ⇒ String
Returns The name of the Elasticsearch index.
26 27 28 |
# File 'lib/jay_api/elasticsearch/index.rb', line 26 def index_name @index_name ||= index_names.first end |
#settings ⇒ JayAPI::Elasticsearch::Indices::Settings
Returns The settings for the index.
57 58 59 60 |
# File 'lib/jay_api/elasticsearch/index.rb', line 57 def settings # DO NOT MEMOIZE! Leave it to the caller. ::JayAPI::Elasticsearch::Indices::Settings.new(client.transport_client, index_name) end |