Class: ElasticGraph::SchemaDefinition::Indexing::Field Private
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::Indexing::Field
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/indexing/field.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents a field in a JSON document during indexing.
Direct Known Subclasses
Class Method Summary collapse
-
.normalized_mapping_hash_for(fields) ⇒ Hash<String, Object>
private
Builds a hash containing the mapping for the provided fields, normalizing it in the same way that the datastore does so that consistency checks between our index configuration and what's in the datastore work properly.
Instance Method Summary collapse
-
#mapping ⇒ Hash<String, Object>
private
The mapping for this field.
Class Method Details
.normalized_mapping_hash_for(fields) ⇒ Hash<String, Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a hash containing the mapping for the provided fields, normalizing it in the same way that the datastore does so that consistency checks between our index configuration and what's in the datastore work properly.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/indexing/field.rb', line 55 def self.normalized_mapping_hash_for(fields) # When an object field has `properties`, the datastore normalizes the mapping by dropping # the `type => object` (it's implicit, as `properties` are only valid on an object...). # OTOH, when there are no properties, the datastore normalizes the mapping by dropping the # empty `properties` entry and instead returning `type => object`. return {"type" => "object"} if fields.empty? # Partition the fields into runtime fields and normal fields based on the presence of runtime_script runtime_fields, normal_fields = fields.partition(&:runtime_field_script) mapping_hash = { "properties" => normal_fields.to_h { |f| [f.name_in_index, f.mapping] } } unless runtime_fields.empty? mapping_hash["runtime"] = runtime_fields.to_h do |f| [f.name_in_index, f.mapping.merge({"script" => {"source" => f.runtime_field_script}})] end end mapping_hash end |
Instance Method Details
#mapping ⇒ Hash<String, Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the mapping for this field. The returned hash should be composed entirely of Ruby primitives that, when converted to a JSON string, match the structure required by Elasticsearch.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/indexing/field.rb', line 33 def mapping @mapping ||= begin raw_mapping = indexing_field_type .to_mapping .merge(Support::HashUtil.stringify_keys(mapping_customizations)) if (object_type = type.fully_unwrapped.as_object_type) && type.list? && mapping_customizations[:type] == "nested" # If it's an object list field using the `nested` type, we need to add a `__counts` field to # the mapping for all of its subfields which are lists. ListCountsMapping.merged_into(raw_mapping, for_type: object_type) else raw_mapping end end end |