Module: ElasticSearchable::Indexing::InstanceMethods
- Defined in:
- lib/elastic_searchable/index.rb
Instance Method Summary collapse
-
#as_json_for_index ⇒ Object
document to index in elasticsearch.
-
#percolate(percolator_query = nil) ⇒ Object
percolate this object to see what registered searches match can be done on transient/non-persisted objects! can be done automatically when indexing using :percolate => true config option www.elasticsearch.org/blog/2011/02/08/percolator.html.
-
#reindex(lifecycle = nil) ⇒ Object
reindex the object in elasticsearch fires after_index callbacks after operation is complete see www.elasticsearch.org/guide/reference/api/index_.html.
- #should_index? ⇒ Boolean
Instance Method Details
#as_json_for_index ⇒ Object
document to index in elasticsearch
124 125 126 127 128 129 130 |
# File 'lib/elastic_searchable/index.rb', line 124 def as_json_for_index original_include_root_in_json = self.class.include_root_in_json self.class.include_root_in_json = false return self.as_json self.class.[:json] ensure self.class.include_root_in_json = original_include_root_in_json end |
#percolate(percolator_query = nil) ⇒ Object
percolate this object to see what registered searches match can be done on transient/non-persisted objects! can be done automatically when indexing using :percolate => true config option www.elasticsearch.org/blog/2011/02/08/percolator.html
139 140 141 142 143 144 145 |
# File 'lib/elastic_searchable/index.rb', line 139 def percolate(percolator_query = nil) body = {:doc => self.as_json_for_index} body[:query] = percolator_query if percolator_query response = ElasticSearchable.request :get, self.class.index_type_path('_percolate'), :json_body => body self.percolations = response['matches'] || [] self.percolations end |
#reindex(lifecycle = nil) ⇒ Object
reindex the object in elasticsearch fires after_index callbacks after operation is complete see www.elasticsearch.org/guide/reference/api/index_.html
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/elastic_searchable/index.rb', line 112 def reindex(lifecycle = nil) query = {} query[:percolate] = "*" if _percolate_callbacks.any? response = ElasticSearchable.request :put, self.class.index_type_path(self.id), :query => query, :json_body => self.as_json_for_index self.index_lifecycle = lifecycle ? lifecycle.to_sym : nil _run_index_callbacks self.percolations = response['matches'] || [] _run_percolate_callbacks if self.percolations.any? end |
#should_index? ⇒ Boolean
131 132 133 134 |
# File 'lib/elastic_searchable/index.rb', line 131 def should_index? [self.class.[:if]].flatten.compact.all? { |m| evaluate_elastic_condition(m) } && ![self.class.[:unless]].flatten.compact.any? { |m| evaluate_elastic_condition(m) } end |