Module: ElasticGraph::SchemaDefinition::Mixins::HasTypeInfo
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_type_info.rb
Overview
Mixin used to specify non-GraphQL type info on schema elements. Exists as a mixin so we can apply the same consistent API to every place we need to use this. Currently it's used in 3 places:
- SchemaElements::ScalarType: allows specification of how scalars are represented in the datastore index.
- SchemaElements::TypeWithSubfields: allows customization of how an object type is represented in the datastore index.
- SchemaElements::Field: allows customization of a specific field over the field type's standard index mapping.
Constant Summary collapse
- CUSTOMIZABLE_DATASTORE_PARAMS =
Set of mapping parameters that it makes sense to allow customization of, based on the Elasticsearch docs.
Set[ :analyzer, :eager_global_ordinals, :enabled, :fields, :format, :index, :meta, # not actually in the doc above. Added to support some `index_configurator` tests on 7.9+. :norms, :null_value, :search_analyzer, :type ]
Instance Method Summary collapse
-
#mapping(**options) ⇒ void
Defines the Elasticsearch/OpenSearch field mapping type and mapping parameters for a field or type.
-
#mapping_options ⇒ Hash<Symbol, Object>
Datastore mapping options.
Instance Method Details
#mapping(**options) ⇒ void
This method returns an undefined value.
Defines the Elasticsearch/OpenSearch field mapping type
and mapping parameters for a field or type.
The options passed here will be included in the generated datastore_config.yaml artifact that ElasticGraph uses to configure
Elasticsearch/OpenSearch.
Can be called multiple times; each time, the options will be merged into the existing options.
This is required on a SchemaElements::ScalarType; without it, ElasticGraph would have no way to know how the datatype should be indexed in the datastore.
On a SchemaElements::Field, this can be used to customize how a field is indexed. For example, String fields are normally
indexed as keywords; to instead index a String
field for full text search, you’d need to configure mapping type: "text".
On a SchemaElements::ObjectType, this can be used to use a specific Elasticsearch/OpenSearch data type for something that is
modeled as an object in GraphQL. For example, we use it for the GeoLocation type so they get indexed in Elasticsearch using the
geo_point type.
87 88 89 90 91 92 93 94 95 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_type_info.rb', line 87 def mapping(**) param_diff = (.keys.to_set - CUSTOMIZABLE_DATASTORE_PARAMS).to_a unless param_diff.empty? raise Errors::SchemaError, "Some configured mapping overrides are unsupported: #{param_diff.inspect}" end .update() end |
#mapping_options ⇒ Hash<Symbol, Object>
Returns datastore mapping options.
21 22 23 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_type_info.rb', line 21 def @mapping_options ||= {} end |