Module: ElasticRecord::Index::Percolator

Included in:
ElasticRecord::Index
Defined in:
lib/elastic_record/index/percolator.rb

Instance Method Summary collapse

Instance Method Details

#all_percolatorsObject



28
29
30
31
32
# File 'lib/elastic_record/index/percolator.rb', line 28

def all_percolators
  if hits = connection.json_get("/_percolator/#{percolator_index_name}/_search?q=*&size=500")['hits']
    hits['hits'].map { |hit| hit['_id'] }
  end
end

#create_percolator(name, elastic_query) ⇒ Object



4
5
6
7
8
9
# File 'lib/elastic_record/index/percolator.rb', line 4

def create_percolator(name, elastic_query)
  unless exists? percolator_index_name
    create percolator_index_name
  end
  connection.json_put "/_percolator/#{percolator_index_name}/#{name}", elastic_query
end

#delete_percolator(name) ⇒ Object



11
12
13
# File 'lib/elastic_record/index/percolator.rb', line 11

def delete_percolator(name)
  connection.json_delete "/_percolator/#{percolator_index_name}/#{name}"
end

#get_percolator(name) ⇒ Object



19
20
21
22
# File 'lib/elastic_record/index/percolator.rb', line 19

def get_percolator(name)
  json = connection.json_get("/_percolator/#{percolator_index_name}/#{name}")
  json['_source'] if json['exists']
end

#percolate(document) ⇒ Object



24
25
26
# File 'lib/elastic_record/index/percolator.rb', line 24

def percolate(document)
  connection.json_get("/#{percolator_index_name}/#{type}/_percolate", 'doc' => document)['matches']
end

#percolator_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/elastic_record/index/percolator.rb', line 15

def percolator_exists?(name)
  !get_percolator(name).nil?
end

#percolator_index_nameObject



39
40
41
# File 'lib/elastic_record/index/percolator.rb', line 39

def percolator_index_name
  @percolator_index_name ||= "percolate_#{alias_name}"
end

#reset_percolatorObject



34
35
36
37
# File 'lib/elastic_record/index/percolator.rb', line 34

def reset_percolator
  delete(percolator_index_name) if exists?(percolator_index_name)
  create(percolator_index_name)
end