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 =
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
-
#_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.
-
#default_prepared_statements ⇒ Object
prepared statements are not supported by Elasticsearch.
-
#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, returning: 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_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.
-
#initialize ⇒ 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, _definitions) ⇒ 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 ⇒ ElasticsearchAdapter
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_keys ⇒ Object
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. 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...
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.
#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.
#default_prepared_statements ⇒ Object
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.
#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, 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_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.
#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
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_types ⇒ Hash
returns a hash of 'ActiveRecord types' -> 'Elasticsearch types' (defined @ +NATIVE_DATABASE_TYPES+)
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
#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:
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
#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
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?
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?
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?
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
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).
#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
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_suffix ⇒ Object
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)
#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
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 :)