Module: ElasticGraph::SchemaDefinition::Mixins::HasIndices
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb
Overview
Provides APIs for defining datastore indices.
Instance Attribute Summary collapse
-
#default_graphql_resolver ⇒ ::Symbol?
readonly
The default GraphQL resolver to use for fields on this type.
Instance Method Summary collapse
-
#derive_indexed_type_fields(name, from_id:, route_with: nil, rollover_with: nil) {|Indexing::DerivedIndexedType| ... } ⇒ void
Configures the ElasticGraph indexer to derive another type from this indexed type, using the
from_idfield as the source of theidof the derived type, and the provided block for the definitions of the derived fields. -
#derived_indexed_types ⇒ Array<Indexing::DerivedIndexedType>
List of derived types for this source type.
-
#index(name, **settings) {|Indexing::Index| ... } ⇒ void
Converts the current type from being an embedded type (that is, a type that is embedded within another indexed type) to an indexed type that resides in the named index definition.
-
#index_def ⇒ Indexing::Index?
The defined index for this type, or nil if no index is defined.
-
#indexed? ⇒ Boolean
True if this type has an index.
-
#override_runtime_metadata(**overrides) ⇒ void
Configures overrides for runtime metadata.
-
#plural_root_query_field_name ⇒ String
The plural name of the entity; used for the root
Queryfield that queries documents of this indexed type. -
#resolve_fields_with(default_resolver_name, **config) ⇒ void
Configures the default GraphQL resolver that will be used to resolve the fields of this type.
-
#root_query_fields(plural:, singular: nil) {|SchemaElements::Field| ... } ⇒ void
Determines what the root
Queryfields will be to query this indexed type. -
#singular_root_query_field_name ⇒ String
The singular name of the entity; used for the root
Queryfield (with anAggregationssuffix) that queries aggregations of this indexed type.
Instance Attribute Details
#default_graphql_resolver ⇒ ::Symbol? (readonly)
Returns the default GraphQL resolver to use for fields on this type.
23 24 25 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 23 def default_graphql_resolver @default_graphql_resolver end |
Instance Method Details
#derive_indexed_type_fields(name, from_id:, route_with: nil, rollover_with: nil) {|Indexing::DerivedIndexedType| ... } ⇒ void
This method returns an undefined value.
Configures the ElasticGraph indexer to derive another type from this indexed type, using the from_id field as
the source of the id of the derived type, and the provided block for the definitions of the derived fields.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 152 def derive_indexed_type_fields( name, from_id:, route_with: nil, rollover_with: nil, &block ) Indexing::DerivedIndexedType.new( source_type: self, destination_type_ref: schema_def_state.type_ref(name).to_final_form, id_source: from_id, routing_value_source: route_with, rollover_timestamp_value_source: rollover_with, &block ).tap { |dit| derived_indexed_types << dit } end |
#derived_indexed_types ⇒ Array<Indexing::DerivedIndexedType>
Returns list of derived types for this source type.
170 171 172 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 170 def derived_indexed_types @derived_indexed_types ||= [] end |
#index(name, **settings) {|Indexing::Index| ... } ⇒ void
Use #root_query_fields on indexed types to name the field that will be exposed on Query.
Indexed types must also define an id field, which ElasticGraph will use as the primary key.
Datastore index settings can also be defined (or overridden) in an environment-specific settings YAML file. Index settings
that you want to configure differently for different environments (such as index.number_of_shards—-production and staging
will probably need different numbers!) should be configured in the per-environment YAML configuration files rather than here.
This method returns an undefined value.
Converts the current type from being an embedded type (that is, a type that is embedded within another indexed type) to an
indexed type that resides in the named index definition. Indexed types are directly indexed into the datastore, and will be
queryable from the root Query type.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 65 def index(name, **settings, &block) unless @can_configure_index raise Errors::SchemaError, "Cannot define an index on `#{self.name}` after initialization is complete. " \ "Indices must be configured during initial type definition." end if @index_def raise Errors::SchemaError, "Cannot define multiple indices on `#{self.name}`. " \ "Only one index per type is supported. An index named `#{@index_def.name}` has already been defined." end @index_def = schema_def_state.factory.new_index(name, settings, self, &block) end |
#index_def ⇒ Indexing::Index?
Returns the defined index for this type, or nil if no index is defined.
93 94 95 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 93 def index_def @index_def end |
#indexed? ⇒ Boolean
Returns true if this type has an index.
98 99 100 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 98 def indexed? !@index_def.nil? end |
#override_runtime_metadata(**overrides) ⇒ void
This method returns an undefined value.
Configures overrides for runtime metadata. The provided runtime metadata values will be persisted in the
runtime_metadata.yaml schema artifact and made available at runtime to elasticgraph-graphql and
elasticgraph-indexer.
179 180 181 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 179 def (**overrides) @runtime_metadata_overrides.merge!(overrides) end |
#plural_root_query_field_name ⇒ String
Returns the plural name of the entity; used for the root Query field that queries documents of this indexed type.
237 238 239 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 237 def plural_root_query_field_name @plural_root_query_field_name || naively_pluralize_type_name(name) end |
#resolve_fields_with(default_resolver_name, **config) ⇒ void
This method returns an undefined value.
Configures the default GraphQL resolver that will be used to resolve the fields of this type. Individual fields can override this using SchemaElements::Field#resolve_with.
86 87 88 89 90 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 86 def resolve_fields_with(default_resolver_name, **config) @default_graphql_resolver = default_resolver_name&.then do SchemaArtifacts::RuntimeMetadata::ConfiguredGraphQLResolver.new(it, config) end end |
#root_query_fields(plural:, singular: nil) {|SchemaElements::Field| ... } ⇒ void
This method returns an undefined value.
Determines what the root Query fields will be to query this indexed type. In addition, this method accepts a block, which you
can use to customize the root query field (such as adding a GraphQL directive to it).
230 231 232 233 234 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 230 def root_query_fields(plural:, singular: nil, &customization_block) @plural_root_query_field_name = plural @singular_root_query_field_name = singular @root_query_fields_customizations = customization_block end |
#singular_root_query_field_name ⇒ String
Returns the singular name of the entity; used for the root Query field (with an Aggregations suffix) that queries
aggregations of this indexed type. If not provided, will derive it from the type name (e.g. converting it to camelCase or
snake_case, depending on configuration).
244 245 246 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_indices.rb', line 244 def singular_root_query_field_name @singular_root_query_field_name || to_field_name(name) end |