module Esse

The es 7.6 deprecate the mapping definition under the type level. That's why we have option to define mappings under both Type and Index. If the index mapping is defined. All the Type mapping will be ignored. Source: www.elastic.co/guide/en/elasticsearch/reference/7.6/removal-of-types.html

Constants

MAPPING_ROOT_KEY
SETTING_ROOT_KEY
VERSION

Public Class Methods

config() { |config| ... } click to toggle source

Block configurations

Esse.config do |conf|
  conf.indices_directory = 'app/indices/directory'
  conf.clusters(:v1) do |cluster|
    cluster.index_prefix = 'backend'
    cluster.client = Elasticsearch::Client.new
    cluster.index_settings = {
      number_of_shards: 2,
      number_of_replicas: 0
    }
  end
end

Inline configurations

Esse.config.indices_directory = 'app/indices/directory'
Esse.config.clusters(:v1).client = Elasticsearch::Client.new
# File lib/esse/core.rb, line 27
def self.config
  @config ||= Config.new
  yield(@config) if block_given?
  @config
end
doc_id!(hash, delete: %w[_id], keep: %w[id]) click to toggle source

Simple helper used to fetch Hash value using Symbol and String keys.

@param hash [Hash] the JSON document @param delete [Array] Removes the hash key and return its value @param keep [Array] Fetch the hash key and return its value @return [Array([Integer, String, nil], Hash)] return the key value and the modified hash

# File lib/esse/core.rb, line 55
def self.doc_id!(hash, delete: %w[_id], keep: %w[id])
  return unless hash.is_a?(Hash)

  id = nil
  modified = nil
  Array(delete).each do |key|
    k = key.to_s if hash.key?(key.to_s)
    k ||= key.to_sym if hash.key?(key.to_sym)
    next unless k

    modified ||= hash.dup
    id = modified.delete(k)
    break if id
  end
  return [id, modified] if id

  modified ||= hash
  Array(keep).each do |key|
    id = modified[key.to_s] || modified[key.to_sym]
    break if id
  end
  [id, modified]
end
synchronize() { |: synchronize(&block)| ... } click to toggle source

Unless in single threaded mode, protects access to any mutable global data structure in Esse. Uses a non-reentrant mutex, so calling code should be careful. In general, this should only be used around the minimal possible code such as Hash#[], Hash#[]=, Hash#delete, Array#<<, and Array#delete.

# File lib/esse/core.rb, line 38
def self.synchronize(&block)
  @single_threaded ? yield : @data_mutex.synchronize(&block)
end
timestamp() click to toggle source

Generates an unique timestamp to be used as a index suffix. Time.now.to_i could also do the job. But I think this format is more readable for humans

# File lib/esse/core.rb, line 45
def self.timestamp
  Time.now.strftime('%Y%m%d%H%M%S')
end