Class: ElasticGraph::Indexer::RecordPreparer

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/indexer/record_preparer.rb

Defined Under Namespace

Modules: Identity Classes: Factory

Instance Method Summary collapse

Constructor Details

#initialize(indexing_preparer_by_scalar_type_name, type_metas) ⇒ RecordPreparer

Returns a new instance of RecordPreparer.



84
85
86
87
88
89
90
91
92
93
# File 'lib/elastic_graph/indexer/record_preparer.rb', line 84

def initialize(indexing_preparer_by_scalar_type_name, type_metas)
  @indexing_preparer_by_scalar_type_name = indexing_preparer_by_scalar_type_name
  @eg_meta_by_field_name_by_concrete_type = type_metas.to_h do |meta|
    [meta.name, meta.eg_meta_by_field_name]
  end

  @types_requiring_typename = type_metas.filter_map do |meta|
    meta.name if meta.requires_typename
  end.to_set
end

Instance Method Details

#prepare_for_index(type_name, record) ⇒ Object

Prepares the given payload for being indexed into the named index. This allows any value or field name conversion to happen before we index the data, to support the few cases where we expect differences between the payload received by the ElasticGraph indexer, and the payload we send to the datastore.

As part of preparing the data, we also drop any ‘record` fields that are not defined in our schema. This allows us to handle events that target multiple indices (e.g. v1 and v2) for the same type. The event can contain the set union of fields and this will take care of dropping any unsupported fields before we attempt to index the record.

Note: this method does not mutate the given ‘record`. Instead it returns a copy with any updates applied to it.



109
110
111
# File 'lib/elastic_graph/indexer/record_preparer.rb', line 109

def prepare_for_index(type_name, record)
  prepare_value_for_indexing(record, type_name)
end