Class: JayAPI::Elasticsearch::Indices::Settings::Blocks

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/indices/settings/blocks.rb

Overview

Represents the block settings of an Elasticsearch index.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Blocks

Returns a new instance of Blocks.

Parameters:



13
14
15
# File 'lib/jay_api/elasticsearch/indices/settings/blocks.rb', line 13

def initialize(settings)
  @settings = settings
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



9
10
11
# File 'lib/jay_api/elasticsearch/indices/settings/blocks.rb', line 9

def settings
  @settings
end

Instance Method Details

#write=(value) ⇒ Object

Sets the index’s write block to the given value. When the write block is set to true the index’s data is read-only, but the index’s settings can still be changed. This allows maintenance tasks to still be performed on the index.

Parameters:

  • value (Boolean)

    The new value for the write block of the index.

Raises:

  • (Elasticsearch::Transport::Transport::Errors::ServerError)

    If an error occurs when trying to set the value of the block.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jay_api/elasticsearch/indices/settings/blocks.rb', line 31

def write=(value)
  unless [true, false].include?(value)
    raise ArgumentError, "Expected 'value' to be true or false, #{value.class} given"
  end

  return if write_blocked? == value

  settings.transport_client.indices.put_settings(
    index: settings.index_name,
    body: { 'blocks.write' => value }
  )
end

#write_blocked?Boolean

Returns True if the Index’s write block has been set to true, false otherwise.

Returns:

  • (Boolean)

    True if the Index’s write block has been set to true, false otherwise.



19
20
21
# File 'lib/jay_api/elasticsearch/indices/settings/blocks.rb', line 19

def write_blocked?
  blocks_settings.fetch('write') == 'true'
end