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::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', 'virtual' => true, 'enabled' => true, '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' }, 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
-
#access_id_fielddata? ⇒ Boolean
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
returns true if the cluster option 'id_field_data' is enabled or not configured.
-
#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) ⇒ 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
-
#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
- #change_mapping_attributes(table_name, name, **options, &block) ⇒ Object (also: #change_mapping_attribute) 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, **options) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
A block for changing mappings, settings & aliases in +table+.
-
#clone_table(table_name, target_name, **options, &block) ⇒ Object
included
from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
clones an entire table 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_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.
-
#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.
- #delete_alias(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #delete_meta(table_name, name, **options) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
- #delete_setting(table_name, name, **options, &block) ⇒ Object included from ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
-
#drop_table(table_name, if_exists: false) ⇒ Array
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_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
-
#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?.
-
#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.
-
#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.
148 149 150 151 152 153 154 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 148 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
62 63 64 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 62 def base_structure_keys @base_structure_keys ||= BASE_STRUCTURE.map { |struct| struct['name'] }.freeze end |
.new_client(config) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 66 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[:username]) rescue ::Elastic::Transport::Transport::ServerError => error raise ::ActiveRecord::ConnectionNotEstablished, error. end |
Instance Method Details
#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.
#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) ⇒ 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...
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 220 def api(namespace, action, arguments = {}, name = 'API', async: false) 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) 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
#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
#change_mapping_attributes(table_name, name, **options, &block) ⇒ Object Also known as: change_mapping_attribute 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, **options) ⇒ 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, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
clones an entire table 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_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.
#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.
#delete_alias(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
#delete_meta(table_name, name, **options) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
#delete_setting(table_name, name, **options, &block) ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements
#drop_table(table_name, if_exists: false) ⇒ Array 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_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
171 172 173 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 171 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+)
207 208 209 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 207 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
#schema_creation ⇒ Object Originally defined in module ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements
overwrite original methods to provide a elasticsearch version
#schema_migration ⇒ Object
:nodoc:
156 157 158 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 156 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
190 191 192 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 190 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?
196 197 198 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 196 def supports_comments_in_create? false end |
#supports_explain? ⇒ Boolean
Does this adapter support explain?
176 177 178 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 176 def supports_explain? false end |
#supports_indexes_in_create? ⇒ Boolean
Does this adapter support creating indexes in the same statement as creating the table?
182 183 184 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 182 def supports_indexes_in_create? 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
161 162 163 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 161 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
166 167 168 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 166 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)
#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
201 202 203 |
# File 'lib/active_record/connection_adapters/elasticsearch_adapter.rb', line 201 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 :)