# frozen_string_literal: true module Esse # @abstract # # A document is a class that represents a single JSON document to be indexed class Document def initialize(entry, **context) @source = item @context = context end # Returns the Elasticsearch `_id` for the document. # # @return [String, Number] The Elasticsearch `_id` for the document # @abstract def id raise NotImplementedError end # Returns the Elasticsearch `_routing` for the item. Elasticsearch # default if this value is not provided is to use the `_id`. # Setting this value to `false` or `nil` will omit sending the # meta-field with your requests and use default routing behaviour. # # @return [String, NilClass, Boolean] The Elasticsearch `_routing` for the document # @abstract def routing end def attributes {} end def to_h { _id: id, }.tap do |hash| hash[:_routing] = routing if routing end end end end