Class: ActiveRecord::ConnectionAdapters::ElasticsearchAdapter

Constant Summary collapse

ADAPTER_NAME =

defines the Elasticsearch adapter name.

"Elasticsearch"
BASE_STRUCTURE =

defines the Elasticsearch 'base' structure, which is always included but cannot be resolved through mappings ...

[
  { 'name' => '_id', 'type' => 'keyword', 'meta' => { 'primary_key' => 'true' } },
  { 'name' => '_index', 'type' => 'keyword', 'virtual' => true },
  { 'name' => '_score', 'type' => 'float', 'virtual' => true },
  { 'name' => '_type', 'type' => 'keyword', 'virtual' => true },
  { 'name' => '_ignored', 'type' => 'boolean', 'virtual' => true }
].freeze
TYPE_MAP =

reinitialize the constant with new types

ActiveRecord::Type::HashLookupTypeMap.new.tap { |m| initialize_type_map(m) }
NATIVE_DATABASE_TYPES =

define native types - which will be used for schema-dumping

{
  primary_key: { name: 'long' }, # maybe this hae to changed to 'keyword'
  string:   { name: 'keyword' },
  blob:     { name: 'binary' },
  datetime: { name: 'date' },
  bigint:   { name: 'long' },
  json:     { name: 'object' }
}.merge(
  TYPE_MAP.keys.map { |key| [key.to_sym, { name: key }] }.to_h
)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElasticsearchAdapter

Returns a new instance of ElasticsearchAdapter.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 147

def initialize(...)
  super

  # transform provided config
  config         = @config.dup

  # move 'username' to 'user'
  config[:user]  = config.delete(:username) if config[:username]

  # append 'port' to 'host'
  config[:host]  += ":#{config.delete(:port)}" if config[:port] && config[:host]

  # move 'host' to 'hosts'
  config[:hosts] = config.delete(:host) if config[:host]

  @connection_parameters = config
end

Class Method Details

.base_structure_keysObject



57
58
59
60
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 57

def base_structure_keys
  # using a class_variable to not reinitialize for descendants
  @@base_structure_keys ||= BASE_STRUCTURE.map { |struct| struct['name'] }.freeze
end

.new_client(config) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 62

def new_client(config)
  # IMPORTANT: remove +adapter+ from config - otherwise we mess up with Faraday::AdapterRegistry
  client_config          = config.except(:adapter)
  # add rails logger manually, if +:log+ is true
  client_config[:logger] = logger if client_config.delete(:log)

  # build an return new client
  ::Elasticsearch::Client.new(client_config)
rescue ::Elastic::Transport::Transport::Errors::Unauthorized
  raise ::ActiveRecord::DatabaseConnectionError.username_error(config[:user])
rescue ::Elastic::Transport::Transport::ServerError => error
  raise ::ActiveRecord::ConnectionNotEstablished, error.message
end

Instance Method Details

#_env_table_name(table_name) ⇒ String Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

recaps a provided +table_name+ with optionally configured +table_name_prefix+ & +table_name_suffix+. This depends on the connection config of the current environment.

Parameters:

  • table_name (String)

Returns:

  • (String)

#access_id_fielddata?Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns true if the cluster option 'id_field_data' is enabled or not configured. This is required to check if a general sorting on the +_id+-field is possible or not.

Returns:

  • (Boolean)

#access_shard_doc?Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns true if +_shard_doc+ field can be accessed through PIT-search.

Returns:

  • (Boolean)

#add_alias(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

-- alias ---------------------------------------------------------------------------------------------------

#add_mapping(table_name, name, type, **options, &block) ⇒ Object Also known as: add_column Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

-- mapping -------------------------------------------------------------------------------------------------

#add_setting(table_name, name, value, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

-- setting -------------------------------------------------------------------------------------------------

#alias_exists?(table_name, alias_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if a alias +alias_name+ within a table +table_name+ exists on the database.

alias_exists?(:developers, 'my-alias')

Parameters:

  • table_name (String)
  • alias_name (String, Symbol)

Returns:

  • (Boolean)

#api(namespace, action, arguments = {}, name = 'API', async: false, log: true) ⇒ Elasticsearch::API::Response, Object

calls the +elasticsearch-api+ endpoints by provided namespace and action. if a block was provided it'll yield the response.body and returns the blocks result. otherwise it will return the response itself...

Parameters:

  • namespace (Symbol)
    • the API namespace (e.g. indices, nodes, sql, ...)
  • action (Symbol)
    • the API action to call in tha namespace
  • arguments (Hash) (defaults to: {})
    • action arguments
  • name (String (frozen)) (defaults to: 'API')
    • the logging name
  • async (Boolean) (defaults to: false)
    • send async (default: false) - currently not supported
  • log (Boolean) (defaults to: true)
    • send log to instrumenter (default: true)

Returns:

  • (Elasticsearch::API::Response, Object)

Raises:

  • (::StandardError)


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 242

def api(namespace, action, arguments = {}, name = 'API', async: false, log: true)
  raise ::StandardError, 'ASYNC api calls are not supported' if async

  # resolve the API target
  target = namespace == :core ? raw_connection : raw_connection.__send__(namespace)

  __send__(:log, "#{namespace}.#{action}", arguments, name, async: async, log: log) do
    response = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
      target.__send__(action, arguments)
    end

    if response.is_a?(::Elasticsearch::API::Response)
      # reverse information for the LogSubscriber - shows the 'query-time' in the logs
      # this works, since we use a referenced hash ...
      arguments[:_qt] = response['took']

      # raise timeouts
      raise(ActiveRecord::StatementTimeout, "Elasticsearch api request failed due a timeout") if response['timed_out']
    end

    response
  end
end

#assume_migrated_upto_version(version) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

#backup_table(table_name, to: nil, close: true) ⇒ String Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

creates a backup (snapshot) of the entire table (index) from provided +table_name+. The backup will be closed, to prevent read/write access. The +target_name+ will be auto-generated, if not provided.

Examples:

backup_table('screenshots', to: 'screenshots-backup-v1')

Parameters:

  • table_name (String)
  • to (String) (defaults to: nil)
    • target_name
  • close (Boolean) (defaults to: true)
    • closes backup after creation (default: true)

Returns:

  • (String)

    backup_name

Raises:

  • (ArgumentError)

#begin_db_transactionObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

Begins the transaction (and turns off auto-committing).

#block_table(table_name, block_name = :write) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

blocks access to the provided table (index) and +block+ name.

Parameters:

  • table_name (String)
  • block_name (Symbol) (defaults to: :write)

    The block to add (one of :read, :write, :read_only or :metadata)

Returns:

  • (Boolean)

    acknowledged status

#change_alias(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#change_mapping(table_name, name, type, **options, &block) ⇒ Object Also known as: change_column Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

will fail unless +recreate:true+ option was provided

#change_mapping_attributes(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#change_mapping_meta(table_name, name, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#change_meta(table_name, name, value, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#change_setting(table_name, name, value, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#change_table(table_name, if_exists: false, recreate: false, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

A block for changing mappings, settings & aliases in +table+.

# change_table() yields a ChangeTableDefinition instance change_table(:suppliers) do |t| t.mapping :name, :string # Other column alterations here end

#clone_table(table_name, target_name, **options) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

clones an entire table (index) with its docs to the provided +target_name+. During cloning, the table will be automatically 'write'-blocked.

Parameters:

  • table_name (String)
  • target_name (String)
  • options (Hash)

Returns:

  • (Boolean)

    acknowledged status

#clone_table_definition(name, target, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

#close_table(table_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Closes an index.

Parameters:

  • table_name (String)

Returns:

  • (Boolean)

    acknowledged status

#close_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Closes indices by provided names.

Parameters:

  • table_names (Array)

Returns:

  • (Array)

    acknowledged status for each provided table

#cluster_health(**options) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns the cluster health

Returns:

  • (Hash)

#cluster_infoHash{Symbol->Unknown Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Returns basic information about the cluster.

Returns:

  • (Hash{Symbol->Unknown)

    ]

#cluster_settingsHash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of current set, none-default settings in flat

Returns:

  • (Hash)

#column_definitions(table_name) ⇒ Array<Hash> Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Returns the list of a table's column names, data types, and default values.

Parameters:

  • table_name (String)

Returns:

  • (Array<Hash>)

See Also:

  • SchemaStatements#columns
  • AbstractMysqlAdapter#column_definitions

#commit_db_transactionObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

Commits the transaction (and turns on auto-committing).

#create_savepointObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

#create_schema_dumper(options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

overwrite original methods to provide a elasticsearch version

#create_table(table_name, force: false, copy_from: nil, if_not_exists: false, **options) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

creates a new table (index). [:force] Set to +true+ to drop an existing table Defaults to false. [:copy_from] Set to an existing index, to copy it's schema. [:if_not_exists] Set to +true+ to skip creation if table already exists. Defaults to false.

Parameters:

  • table_name (String)
  • force (Boolean) (defaults to: false)
    • force a drop on the existing table (default: false)
  • copy_from (nil, String) (defaults to: nil)
    • copy schema from existing table
  • options (Hash)

Returns:

  • (Boolean)

    acknowledged status

#create_table_definition(name, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

overwrite original methods to provide a elasticsearch version

#data_source_exists?(name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if the data source +name+ exists on the database.

data_source_exists?(:ebooks)

Parameters:

  • name (String, Symbol)

Returns:

  • (Boolean)

See Also:

  • SchemaStatements#data_source_exists?

#data_sourcesArray<String> Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Returns the relation names usable to back Active Record models. For Elasticsearch this means all indices - which also includes system +dot+ '.' indices.

Returns:

  • (Array<String>)

See Also:

  • SchemaStatements#data_sources

#default_prepared_statementsObject

prepared statements are not supported by Elasticsearch. documentation for mysql prepares statements @ https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html



186
187
188
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 186

def default_prepared_statements
  false
end

#drop_table(table_name, if_exists: false) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

drops an index [:if_exists] Set to +true+ to only drop the table if it exists. Defaults to false.

Parameters:

  • table_name (String)
  • if_exists (Boolean) (defaults to: false)

Returns:

  • (Boolean)

    acknowledged status

#exec_delete(query, name = nil, binds = []) ⇒ Integer Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

Executes delete +query+ statement in the context of this connection using +binds+ as the bind substitutes. +name+ is logged along with the executed +query+ arguments. expects a integer as return.

Returns:

  • (Integer)

#exec_insert(query, name = nil, binds = [], _pk = nil, _sequence_name = nil, returning: nil) ⇒ ElasticsearchRecord::Result Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

Executes insert +query+ statement in the context of this connection using +binds+ as the bind substitutes. +name+ is logged along with the executed +query+ arguments.

#exec_rollback_db_transactionObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

rollback transaction

#exec_rollback_to_savepointObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

#exec_update(query, name = nil, binds = []) ⇒ Integer Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

Executes update +query+ statement in the context of this connection using +binds+ as the bind substitutes. +name+ is logged along with the executed +query+ arguments. expects a integer as return.

Returns:

  • (Integer)

#last_inserted_id(result) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

returns the last inserted id from the result. called through +#insert+

#lookup_cast_type_from_column(column) ⇒ ActiveRecord::ConnectionAdapters::Elasticsearch::Type::MulticastValue Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

lookups from building the @columns_hash. since Elasticsearch has the "feature" to provide multicast values on any type, we need to fetch them ... you know, ES can return an integer or an array of integers for any column ...

#mapping_exists?(table_name, mapping_name, type = nil) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if a mapping +mapping_name+ within a table +table_name+ exists on the database.

mapping_exists?(:developers, :status, :integer)

Parameters:

  • table_name (String, Symbol)
  • mapping_name (String, Symbol)

Returns:

  • (Boolean)

#max_result_window(table_name) ⇒ Integer Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns the maximum allowed size for queries for the provided +table_name+. The query will raise an ActiveRecord::StatementInvalid if the requested limit is above this value.

Returns:

  • (Integer)

#meta_exists?(table_name, meta_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if a meta +meta_name+ within a table +table_name+ exists on the database.

meta_exists?(:developers, 'class')

Parameters:

  • table_name (String)
  • meta_name (String, Symbol)

Returns:

  • (Boolean)

#migrations_pathsObject

overwrite method to provide a Elasticsearch path



180
181
182
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 180

def migrations_paths
  @config[:migrations_paths] || ['db/migrate_elasticsearch']
end

#native_database_typesHash

returns a hash of 'ActiveRecord types' -> 'Elasticsearch types' (defined @ +NATIVE_DATABASE_TYPES+)

Returns:

  • (Hash)


228
229
230
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 228

def native_database_types # :nodoc:
  NATIVE_DATABASE_TYPES
end

#new_column_from_field(_table_name, field, _definitions) ⇒ ActiveRecord::ConnectionAdapters::Column Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

creates a new column object from provided field Hash

Parameters:

  • _table_name (String)
  • field (Hash)

Returns:

  • (ActiveRecord::ConnectionAdapters::Column)

See Also:

  • SchemaStatements#columns
  • MySQL::SchemaStatements#new_column_from_field

#open_table(table_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Opens a closed index.

Parameters:

  • table_name (String)

Returns:

  • (Boolean)

    acknowledged status

#open_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Opens closed indices.

Parameters:

  • table_names (Array)

Returns:

  • (Array)

    acknowledged status for each provided table

#primary_keys(table_name) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Returns a array of tables primary keys. PLEASE NOTE: Elasticsearch does not have a concept of primary key. The only thing that uniquely identifies a document is the index together with the +_id+. To support this concept we simulate this through the +_meta+ field (from the index).

As a alternative, the primary_key can also be provided through the mappings +meta+ field.

see @ https://www.elastic.co/guide/en/elasticsearch/reference/8.5/mapping-meta-field.html

Parameters:

  • table_name (String)

See Also:

  • AbstractMysqlAdapter#primary_keys

#quoted_falseObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting

#quoted_trueObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting

#refresh_table(table_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

refresh an index. A refresh makes recent operations performed on one or more indices available for search. raises an exception if the index could not be found.

Parameters:

  • table_name (String)

Returns:

  • (Boolean)

    result state (returns false if refreshing failed)

#refresh_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

refresh indices by provided names.

Parameters:

  • table_names (Array)

Returns:

  • (Array)

    result state (returns false if refreshing failed)

#reindex_table(table_name, target_name, **options) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Copies documents from a source to a destination.

Parameters:

  • table_name (String)
  • target_name (String)
  • options (Hash)

Returns:

  • (Hash)

    reindex stats

#release_savepointObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

#remove_alias(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#remove_mapping(table_name, name, **options) ⇒ Object Also known as: remove_column Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#remove_meta(table_name, name, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#remove_setting(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

#rename_table(table_name, target_name, timeout: nil, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

renames a table (index) by executing multiple steps:

  • clone table
  • wait for 'green' state
  • drop old table The +timeout+ option will define how long to wait for the 'green' state.

Parameters:

  • table_name (String)
  • target_name (String)
  • timeout (String (frozen)) (defaults to: nil)

    (default: '30s')

  • options (Hash)
    • additional 'clone' options (like settings, alias, ...)

#restore_table(table_name, from:, timeout: nil, open: true, drop_backup: false) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

restores a entire table (index) from provided +target_name+. The +table_name+ will be dropped, if exists. The +from+ will persist, if not provided +drop_backup:true+.

Examples:

restore_table('screenshots', from: 'screenshots-backup-v1')

Parameters:

  • table_name (String)
  • from (String)
  • timeout (String (frozen)) (defaults to: nil)
    • renaming timout (default: '30s')
  • open (Boolean) (defaults to: true)
    • opens restored backup after creation (default: true)

Returns:

  • (Boolean)

    acknowledged status

Raises:

  • (ArgumentError)

#schema_creationObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

overwrite original methods to provide a elasticsearch version

#schema_migrationObject

:nodoc:



165
166
167
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 165

def schema_migration # :nodoc:
  ElasticsearchRecord::SchemaMigration.new(self)
end

#select_count(arel, name = "Count", async: false) ⇒ Integer Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

executes a count query for provided arel

Returns:

  • (Integer)

#select_multiple(arels, name = "Multi", async: false) ⇒ ElasticsearchRecord::Result Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

executes a msearch for provided arels

#setting_exists?(table_name, setting_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if a setting +setting_name+ within a table +table_name+ exists on the database. The provided +setting_name+ must be flat!

setting_exists?(:developers, 'index.number_of_replicas')

Parameters:

  • table_name (String)
  • setting_name (String, Symbol)

Returns:

  • (Boolean)

#supports_comments?Boolean

Does this adapter support metadata comments on database objects (tables)? PLEASE NOTE: Elasticsearch does only support comments on mappings as 'meta' information. This method only relies to create comments on tables (indices) and is therefore not supported. see @ ActiveRecord::ConnectionAdapters::SchemaStatements#create_table

Returns:

  • (Boolean)


211
212
213
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 211

def supports_comments?
  false
end

#supports_comments_in_create?Boolean

Can comments for tables, columns, and indexes be specified in create/alter table statements? see @ ActiveRecord::ConnectionAdapters::ElasticsearchAdapter#supports_comments?

Returns:

  • (Boolean)


217
218
219
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 217

def supports_comments_in_create?
  false
end

#supports_explain?Boolean

Does this adapter support explain?

Returns:

  • (Boolean)


197
198
199
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 197

def supports_explain?
  false
end

#supports_indexes_in_create?Boolean

Does this adapter support creating indexes in the same statement as creating the table?

Returns:

  • (Boolean)


203
204
205
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 203

def supports_indexes_in_create?
  false
end

#supports_transactions?Boolean

Does this adapter support transactions in general? HINT: This is +NOT* an official setting and only introduced to ElasticsearchRecord

Returns:

  • (Boolean)


192
193
194
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 192

def supports_transactions?
  false
end

#table_aliases(table_name) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of all aliases by provided table_name (index).

Parameters:

  • table_name (String)

Returns:

  • (Hash)

#table_exists?(table_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Checks to see if the table +table_name+ exists on the database.

table_exists?(:developers)

Parameters:

  • table_name (String, Symbol)

Returns:

  • (Boolean)

See Also:

  • SchemaStatements#table_exists?

#table_mappings(table_name) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of all mappings by provided table_name (index)

Parameters:

  • table_name (String)

Returns:

  • (Hash)

#table_metas(table_name) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of all meta data by provided table_name (index). HINT: +_meta+ is resolved from the table mappings

Parameters:

  • table_name (String)

Returns:

  • (Hash)

#table_name_prefixObject

provide a table_name_prefix from the configuration to create & restrict schema creation



170
171
172
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 170

def table_name_prefix
  @config.fetch(:table_name_prefix, '')
end

#table_name_suffixObject

provide a table_name_suffix from the configuration to create & restrict schema creation



175
176
177
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 175

def table_name_suffix
  @config.fetch(:table_name_suffix, '')
end

#table_schema(table_name, features = [:aliases, :mappings, :settings]) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of the full definition of the provided table_name (index). (includes settings, mappings & aliases)

Parameters:

  • table_name (String)
  • features (Array, Symbol) (defaults to: [:aliases, :mappings, :settings])

Returns:

  • (Hash)

#table_settings(table_name, flat_settings = true) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns a hash of all settings by provided table_name

Parameters:

  • table_name (String)
  • flat_settings (Boolean) (defaults to: true)

    (default: true)

Returns:

  • (Hash)

#table_state(table_name) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

returns information about number of primaries and replicas, document counts, disk size, ... by provided table_name (index).

Parameters:

  • table_name (String)

Returns:

  • (Hash)

#tablesArray<String> Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

Returns an array of table names defined in the database. For Elasticsearch this means all normal indices (no system +dot+ '.' indices)

Returns:

  • (Array<String>)

See Also:

  • SchemaStatements#tables

#transactionObject Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions

#truncate_table(table_name) ⇒ Boolean Also known as: truncate Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

truncates index by provided name. HINT: Elasticsearch does not have a +truncate+ concept:

  • so we have to store the current index' schema
  • drop the index
  • and create it again

Parameters:

  • table_name (String)

Returns:

  • (Boolean)

    acknowledged status

#truncate_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

truncate indices by provided names.

Parameters:

  • table_names (Array)

Returns:

  • (Array)

    acknowledged status for each provided table

#type_to_sql(type) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

transforms provided schema-type to a sql-type overwrite original methods to provide a elasticsearch version

Parameters:

  • type (String, Symbol)

#unblock_table(table_name, block_name = nil) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

unblocks access to the provided table (index) and +block+ name. provide a nil-value to unblock all blocks, otherwise provide the blocked name.

Parameters:

  • table_name (String)
  • block_name (Symbol) (defaults to: nil)

    The block to add (one of :read, :write, :read_only or :metadata)

Returns:

  • (Boolean)

    acknowledged status

#update_table_definition(name, base = self, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements

overwrite original methods to provide a elasticsearch version

#use_metadata_table?Boolean

disable metadata tables

Returns:

  • (Boolean)


222
223
224
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 222

def  # :nodoc:
  false
end

#write_query?(query) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements

detects if a query is a write query. since we don't provide a simple string / hash we can now access the query-object and ask for it :)

Parameters:

Returns:

  • (Boolean)

See Also:

  • DatabaseStatements#write_query?