Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Using elasticsearch query DSL directly (or: doing queries not supported by the DSL)

maciejkowalski edited this page Sep 24, 2012 · 3 revisions

Tire supports two types of queries:

  1. Queries using the Tire DSL
  2. Queries the elastic search query REST DSL directly

In this section we'll discuss #2.

The most obvious utility for querying the REST DSL is when you either

  • A query need a feature not supported by the Tire DSL.
  • An application is migrated from another integration to Tire (e.g escargot)
  • A developer prefers the REST DSL.

Please keep in mind that the Tire query logging feature, that helps in debugging, does not work for the REST DSL.

For queries not supported by the Tire query DSL use 'Tire.search' directly like:

# Will match all documents in the 'events' elastic search index 'events' collection
search_results = Tire.search 'events', :query => {"match_all" => {}}

for result in search_results
  logger.debug "This is a search result: #{result}"
end

Also please remember to set pagination variables. Otherwise pagination will NOT work correctly.

search_results = Tire.search('events', :query => {"match_all" => {}}).results
search_results.options[:per_page] = 5
search_results.options[:page] = params[:page] || 1