Class: ActiveRecord::ConnectionAdapters::ElasticsearchAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::ElasticsearchAdapter
- Includes:
- ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements, ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting, ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements, ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements, ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions, ActiveRecord::ConnectionAdapters::Elasticsearch::UnsupportedImplementation
- Defined in:
- lib/active_record/connection_adapters/elasticsearch_adapter.rb
Constant Summary collapse
- 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
-
#_env_table_name(table_name) ⇒ String
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
recaps a provided +table_name+ with optionally configured +table_name_prefix+ & +table_name_suffix+.
-
#access_id_fielddata? ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns true if the cluster option 'id_field_data' is enabled or not configured.
-
#access_shard_doc? ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns true if +_shard_doc+ field can be accessed through PIT-search.
-
#add_alias(table_name, name, **options, &block) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-- alias ---------------------------------------------------------------------------------------------------.
-
#add_mapping(table_name, name, type, **options, &block) ⇒ Object
(also: #add_column)
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-- mapping -------------------------------------------------------------------------------------------------.
-
#add_setting(table_name, name, value, **options, &block) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-- setting -------------------------------------------------------------------------------------------------.
-
#alias_exists?(table_name, alias_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if a alias +alias_name+ within a table +table_name+ exists on the database.
-
#api(namespace, action, arguments = {}, name = 'API', async: false, log: true) ⇒ Elasticsearch::API::Response, Object
calls the +elasticsearch-api+ endpoints by provided namespace and action.
- #assume_migrated_upto_version(version) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
-
#backup_table(table_name, to: nil, close: true) ⇒ String
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
creates a backup (snapshot) of the entire table (index) from provided +table_name+.
-
#begin_db_transaction ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
Begins the transaction (and turns off auto-committing).
-
#block_table(table_name, block_name = :write) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
blocks access to the provided table (index) and +block+ name.
- #change_alias(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-
#change_mapping(table_name, name, type, **options, &block) ⇒ Object
(also: #change_column)
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
will fail unless +recreate:true+ option was provided.
- #change_mapping_attributes(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #change_mapping_meta(table_name, name, **options) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #change_meta(table_name, name, value, **options) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #change_setting(table_name, name, value, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-
#change_table(table_name, if_exists: false, recreate: false, **options, &block) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
A block for changing mappings, settings & aliases in +table+.
-
#clone_table(table_name, target_name, **options) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
clones an entire table (index) with its docs to the provided +target_name+.
- #clone_table_definition(name, target, **options) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
-
#close_table(table_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Closes an index.
-
#close_tables(*table_names) ⇒ Array
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Closes indices by provided names.
-
#cluster_health(**options) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns the cluster health.
-
#cluster_info ⇒ Hash{Symbol->Unknown
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns basic information about the cluster.
-
#cluster_settings ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of current set, none-default settings in flat.
-
#column_definitions(table_name) ⇒ Array<Hash>
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns the list of a table's column names, data types, and default values.
-
#commit_db_transaction ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
Commits the transaction (and turns on auto-committing).
- #create_savepoint ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
-
#create_schema_dumper(options) ⇒ Object
included
from 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
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
creates a new table (index).
-
#create_table_definition(name, **options) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
overwrite original methods to provide a elasticsearch version.
-
#data_source_exists?(name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if the data source +name+ exists on the database.
-
#data_sources ⇒ Array<String>
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns the relation names usable to back Active Record models.
-
#drop_table(table_name, if_exists: false) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
drops an index [:if_exists] Set to +true+ to only drop the table if it exists.
-
#exec_delete(query, name = nil, binds = []) ⇒ Integer
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
Executes delete +query+ statement in the context of this connection using +binds+ as the bind substitutes.
-
#exec_insert(query, name = nil, binds = [], _pk = nil, _sequence_name = nil) ⇒ ElasticsearchRecord::Result
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
Executes insert +query+ statement in the context of this connection using +binds+ as the bind substitutes.
-
#exec_query(query, name = "QUERY", binds = [], prepare: false, async: false) ⇒ ElasticsearchRecord::Result
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
gets called for all queries - a +ElasticsearchRecord::Query+ must be provided.
-
#exec_rollback_db_transaction ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
rollback transaction.
- #exec_rollback_to_savepoint ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
-
#exec_update(query, name = nil, binds = []) ⇒ Integer
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
Executes update +query+ statement in the context of this connection using +binds+ as the bind substitutes.
-
#execute(query, name = nil, async: false) ⇒ ElasticsearchRecord::Result
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
Executes the query object in the context of this connection and returns the raw result from the connection adapter.
-
#initialize(*args) ⇒ ElasticsearchAdapter
constructor
A new instance of ElasticsearchAdapter.
-
#last_inserted_id(result) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
returns the last inserted id from the result.
-
#lookup_cast_type_from_column(column) ⇒ ActiveRecord::ConnectionAdapters::Elasticsearch::Type::MulticastValue
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
lookups from building the @columns_hash.
-
#mapping_exists?(table_name, mapping_name, type = nil) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if a mapping +mapping_name+ within a table +table_name+ exists on the database.
-
#max_result_window(table_name) ⇒ Integer
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns the maximum allowed size for queries for the provided +table_name+.
-
#meta_exists?(table_name, meta_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if a meta +meta_name+ within a table +table_name+ exists on the database.
-
#migrations_paths ⇒ Object
overwrite method to provide a Elasticsearch path.
-
#native_database_types ⇒ Hash
returns a hash of 'ActiveRecord types' -> 'Elasticsearch types' (defined @ +NATIVE_DATABASE_TYPES+).
-
#new_column_from_field(_table_name, field) ⇒ ActiveRecord::ConnectionAdapters::Column
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
creates a new column object from provided field Hash.
-
#open_table(table_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Opens a closed index.
-
#open_tables(*table_names) ⇒ Array
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Opens closed indices.
-
#primary_keys(table_name) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns a array of tables primary keys.
- #quoted_false ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting
- #quoted_true ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting
-
#refresh_table(table_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
refresh an index.
-
#refresh_tables(*table_names) ⇒ Array
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
refresh indices by provided names.
-
#reindex_table(table_name, target_name, **options) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Copies documents from a source to a destination.
- #release_savepoint ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
- #remove_alias(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #remove_mapping(table_name, name, **options) ⇒ Object (also: #remove_column) included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #remove_meta(table_name, name, **options) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #remove_setting(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-
#rename_table(table_name, target_name, timeout: nil, **options) ⇒ Object
included
from 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.
-
#restore_table(table_name, from:, timeout: nil, open: true, drop_backup: false) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
restores a entire table (index) from provided +target_name+.
-
#schema_creation ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
overwrite original methods to provide a elasticsearch version.
-
#schema_migration ⇒ Object
:nodoc:.
-
#select_count(arel, name = "Count", async: false) ⇒ Integer
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
executes a count query for provided arel.
-
#select_multiple(arels, name = "Multi", async: false) ⇒ ElasticsearchRecord::Result
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
executes a msearch for provided arels.
-
#setting_exists?(table_name, setting_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if a setting +setting_name+ within a table +table_name+ exists on the database.
-
#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.
-
#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?.
-
#supports_explain? ⇒ Boolean
Does this adapter support explain?.
-
#supports_indexes_in_create? ⇒ Boolean
Does this adapter support creating indexes in the same statement as creating the table?.
-
#supports_transactions? ⇒ Boolean
Does this adapter support transactions in general? HINT: This is +NOT* an official setting and only introduced to ElasticsearchRecord.
-
#table_aliases(table_name) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of all aliases by provided table_name (index).
-
#table_exists?(table_name) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Checks to see if the table +table_name+ exists on the database.
-
#table_mappings(table_name) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of all mappings by provided table_name (index).
-
#table_metas(table_name) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of all meta data by provided table_name (index).
-
#table_name_prefix ⇒ Object
provide a table_name_prefix from the configuration to create & restrict schema creation.
-
#table_name_suffix ⇒ Object
provide a table_name_suffix from the configuration to create & restrict schema creation.
-
#table_schema(table_name, features = [:aliases, :mappings, :settings]) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of the full definition of the provided table_name (index).
-
#table_settings(table_name, flat_settings = true) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of all settings by provided table_name.
-
#table_state(table_name) ⇒ Hash
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns information about number of primaries and replicas, document counts, disk size, ...
-
#tables ⇒ Array<String>
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns an array of table names defined in the database.
- #transaction ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
-
#truncate_table(table_name) ⇒ Boolean
(also: #truncate)
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
truncates index by provided name.
-
#truncate_tables(*table_names) ⇒ Array
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
truncate indices by provided names.
-
#type_to_sql(type) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
transforms provided schema-type to a sql-type overwrite original methods to provide a elasticsearch version.
-
#unblock_table(table_name, block_name = nil) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
unblocks access to the provided table (index) and +block+ name.
-
#update_table_definition(name, base = self, **options) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
overwrite original methods to provide a elasticsearch version.
-
#use_metadata_table? ⇒ Boolean
disable metadata tables.
-
#write_query?(query) ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
detects if a query is a write query.
Constructor Details
#initialize(*args) ⇒ ElasticsearchAdapter
Returns a new instance of ElasticsearchAdapter.
156 157 158 159 160 161 162 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 156 def initialize(*args) super(*args) # 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 @prepared_statements = false end |
Class Method Details
.base_structure_keys ⇒ Object
70 71 72 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 70 def base_structure_keys @base_structure_keys ||= BASE_STRUCTURE.map { |struct| struct['name'] }.freeze end |
.new_client(config) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 74 def new_client(config) # IMPORTANT: remove +adapter+ from config - otherwise we mess up with Faraday::AdapterRegistry client = ::Elasticsearch::Client.new(config.except(:adapter)) client.ping unless config[:ping] == false client rescue ::Elastic::Transport::Transport::Errors::Unauthorized raise ActiveRecord::DatabaseConnectionError.username_error(config[:user]) rescue ::Elastic::Transport::Transport::ServerError => error raise ::ActiveRecord::ConnectionNotEstablished, error. 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.
#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.
#access_shard_doc? ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns true if +_shard_doc+ field can be accessed through PIT-search.
#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')
#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...
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 235 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 ? @connection : @connection.__send__(namespace) 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.
#begin_db_transaction ⇒ Object 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.
#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.
#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.
#close_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Closes indices by provided names.
#cluster_health(**options) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns the cluster health
#cluster_info ⇒ Hash{Symbol->Unknown Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
Returns basic information about the cluster.
#cluster_settings ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of current set, none-default settings in flat
#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.
#commit_db_transaction ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
Commits the transaction (and turns on auto-committing).
#create_savepoint ⇒ Object 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.
#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)
#data_sources ⇒ Array<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.
#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.
#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.
#exec_insert(query, name = nil, binds = [], _pk = nil, _sequence_name = 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_query(query, name = "QUERY", binds = [], prepare: false, async: false) ⇒ ElasticsearchRecord::Result Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
gets called for all queries - a +ElasticsearchRecord::Query+ must be provided.
#exec_rollback_db_transaction ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Transactions
rollback transaction
#exec_rollback_to_savepoint ⇒ Object 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.
#execute(query, name = nil, async: false) ⇒ ElasticsearchRecord::Result Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
Executes the query object in the context of this connection and returns the raw result from the connection adapter.
#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)
#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.
#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')
#migrations_paths ⇒ Object
overwrite method to provide a Elasticsearch path
179 180 181 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 179 def migrations_paths @config[:migrations_paths] || ['db/migrate_elasticsearch'] end |
#native_database_types ⇒ Hash
returns a hash of 'ActiveRecord types' -> 'Elasticsearch types' (defined @ +NATIVE_DATABASE_TYPES+)
221 222 223 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 221 def native_database_types # :nodoc: NATIVE_DATABASE_TYPES end |
#new_column_from_field(_table_name, field) ⇒ ActiveRecord::ConnectionAdapters::Column Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
creates a new column object from provided field Hash
#open_table(table_name) ⇒ Boolean Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Opens a closed index.
#open_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Opens closed indices.
#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
#quoted_false ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::Quoting
#quoted_true ⇒ Object 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.
#refresh_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
refresh indices by provided names.
#reindex_table(table_name, target_name, **options) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
Copies documents from a source to a destination.
#release_savepoint ⇒ Object 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.
#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+.
#schema_creation ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
overwrite original methods to provide a elasticsearch version
#schema_migration ⇒ Object
:nodoc:
164 165 166 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 164 def schema_migration # :nodoc: @schema_migration ||= ElasticsearchRecord::SchemaMigration end |
#select_count(arel, name = "Count", async: false) ⇒ Integer Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::DatabaseStatements
executes a count query for provided arel
#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')
#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
204 205 206 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 204 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?
210 211 212 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 210 def supports_comments_in_create? false end |
#supports_explain? ⇒ Boolean
Does this adapter support explain?
190 191 192 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 190 def supports_explain? false end |
#supports_indexes_in_create? ⇒ Boolean
Does this adapter support creating indexes in the same statement as creating the table?
196 197 198 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 196 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
185 186 187 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 185 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).
#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)
#table_mappings(table_name) ⇒ Hash Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns a hash of all mappings by provided table_name (index)
#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
#table_name_prefix ⇒ Object
provide a table_name_prefix from the configuration to create & restrict schema creation
169 170 171 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 169 def table_name_prefix @config.fetch(:table_name_prefix, '') end |
#table_name_suffix ⇒ Object
provide a table_name_suffix from the configuration to create & restrict schema creation
174 175 176 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 174 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)
#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
#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).
#tables ⇒ Array<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)
#transaction ⇒ Object 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
#truncate_tables(*table_names) ⇒ Array Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
truncate indices by provided names.
#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
#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.
#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
215 216 217 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 215 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 :)