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/exceptions.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, MethodNotImplemented, 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

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.

Examples:

SearchFlip.aliases(actions: [
  { remove: { index: "test1", alias: "alias1" }},
  { add: { index: "test2", alias: "alias1" }}
])

Parameters:

  • payload (Hash)

    The raw request payload

Returns:



79
80
81
# File 'lib/search_flip.rb', line 79

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.

Examples:

SearchFlip.msearch [ProductIndex.match_all, CommentIndex.match_all]

Parameters:

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/search_flip.rb', line 53

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

.versionString

Queries and returns the ElasticSearch version used.

Examples:

SearchFlip.version # => e.g. 2.4.1

Returns:

  • (String)

    The ElasticSearch version



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