Module: SearchFlip
- Defined in:
- lib/search_flip.rb,
lib/search_flip/bulk.rb,
lib/search_flip/json.rb,
lib/search_flip/index.rb,
lib/search_flip/model.rb,
lib/search_flip/config.rb,
lib/search_flip/result.rb,
lib/search_flip/version.rb,
lib/search_flip/criteria.rb,
lib/search_flip/response.rb,
lib/search_flip/filterable.rb,
lib/search_flip/aggregation.rb,
lib/search_flip/http_client.rb,
lib/search_flip/aggregatable.rb,
lib/search_flip/post_filterable.rb
Defined Under Namespace
Modules: Aggregatable, Filterable, Index, Model, PostFilterable Classes: Aggregation, Bulk, ConnectionError, Criteria, HTTPClient, JSON, NotSupportedError, Response, ResponseError, Result
Constant Summary collapse
- Config =
{ index_prefix: nil, base_url: "http://127.0.0.1:9200", bulk_limit: 1_000, auto_refresh: false }
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.aliases(payload) ⇒ SearchFlip::Response
Used to manipulate, ie add and remove index aliases.
-
.msearch(criterias) ⇒ Array<SearchFlip::Response>
Uses the ElasticSearch Multi Search API to execute multiple search requests within a single request.
-
.version ⇒ String
Queries and returns the ElasticSearch version used.
Class Method Details
.aliases(payload) ⇒ SearchFlip::Response
Used to manipulate, ie add and remove index aliases. Raises an SearchFlip::ResponseError in case any errors occur.
78 79 80 |
# File 'lib/search_flip.rb', line 78 def self.aliases(payload) SearchFlip::HTTPClient.headers(accept: "application/json", content_type: "application/json").post("#{SearchFlip::Config[:base_url]}/_aliases", body: SearchFlip::JSON.generate(payload)) end |
.msearch(criterias) ⇒ Array<SearchFlip::Response>
Uses the ElasticSearch Multi Search API to execute multiple search requests within a single request. Raises SearchFlip::ResponseError in case any errors occur.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/search_flip.rb', line 52 def self.msearch(criterias) payload = criterias.flat_map do |criteria| [SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, type: criteria.target.type_name), SearchFlip::JSON.generate(criteria.request)] end payload = payload.join("\n") payload << "\n" SearchFlip::HTTPClient.headers(accept: "application/json", content_type: "application/x-ndjson").post("#{SearchFlip::Config[:base_url]}/_msearch", body: payload).parse["responses"].map.with_index do |response, index| SearchFlip::Response.new(criterias[index], response) end end |
.version ⇒ String
Queries and returns the ElasticSearch version used.
10 11 12 |
# File 'lib/search_flip/config.rb', line 10 def self.version @version ||= SearchFlip::HTTPClient.get("#{Config[:base_url]}/").parse["version"]["number"] end |