Module: ElasticRecord::Index::Percolator
- Included in:
- ElasticRecord::Index
- Defined in:
- lib/elastic_record/index/percolator.rb
Instance Method Summary collapse
- #all_percolators ⇒ Object
- #create_percolator(name, elastic_query) ⇒ Object
- #create_percolator_index ⇒ Object
- #delete_percolator(name) ⇒ Object
- #delete_percolator_index ⇒ Object
- #get_percolator(name) ⇒ Object
- #percolate(document) ⇒ Object
- #percolator_exists?(name) ⇒ Boolean
- #percolator_name ⇒ Object
- #reset_percolators ⇒ Object
Instance Method Details
#all_percolators ⇒ Object
26 27 28 29 30 |
# File 'lib/elastic_record/index/percolator.rb', line 26 def all_percolators if hits = connection.json_get("/#{percolator_name}/.percolator/_search?q=*&size=500")['hits'] hits['hits'].map { |hit| hit['_id'] } end end |
#create_percolator(name, elastic_query) ⇒ Object
4 5 6 |
# File 'lib/elastic_record/index/percolator.rb', line 4 def create_percolator(name, elastic_query) connection.json_put "/#{percolator_name}/.percolator/#{name}", elastic_query end |
#create_percolator_index ⇒ Object
32 33 34 |
# File 'lib/elastic_record/index/percolator.rb', line 32 def create_percolator_index create(percolator_name) unless exists?(percolator_name) end |
#delete_percolator(name) ⇒ Object
8 9 10 |
# File 'lib/elastic_record/index/percolator.rb', line 8 def delete_percolator(name) connection.json_delete "/#{percolator_name}/.percolator/#{name}" end |
#delete_percolator_index ⇒ Object
36 37 38 |
# File 'lib/elastic_record/index/percolator.rb', line 36 def delete_percolator_index delete(percolator_name) if exists?(percolator_name) end |
#get_percolator(name) ⇒ Object
16 17 18 19 |
# File 'lib/elastic_record/index/percolator.rb', line 16 def get_percolator(name) json = connection.json_get("/#{percolator_name}/.percolator/#{name}") json['_source'] if json['found'] end |
#percolate(document) ⇒ Object
21 22 23 24 |
# File 'lib/elastic_record/index/percolator.rb', line 21 def percolate(document) hits = connection.json_get("/#{percolator_name}/#{type}/_percolate", 'doc' => document)['matches'] hits.map { |hits| hits['_id'] } end |
#percolator_exists?(name) ⇒ Boolean
12 13 14 |
# File 'lib/elastic_record/index/percolator.rb', line 12 def percolator_exists?(name) connection.head("/#{percolator_name}/.percolator/#{name}") == '200' end |
#percolator_name ⇒ Object
45 46 47 |
# File 'lib/elastic_record/index/percolator.rb', line 45 def percolator_name "#{alias_name}_percolator" end |
#reset_percolators ⇒ Object
40 41 42 43 |
# File 'lib/elastic_record/index/percolator.rb', line 40 def reset_percolators delete_percolator_index create_percolator_index end |