Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:44:02+00:00 2026-06-08T07:44:02+00:00

Using Elasticsearch with Rails 3 and tire gem. I have got facets to work

  • 0

Using Elasticsearch with Rails 3 and tire gem.

I have got facets to work on a couple of fields, but I now have a special requirement and not sure it is possible.
I have two fields on my model Project that both store the same values: Country1 and Country2

The user is allowed to store up to two countries for a project. The drop down menus on both are the same. Neither field is required.

What I would like is a single facet that ‘merges’ the values from Country1 and Country2 and would handle clicking on those facets intelligently (i.e. would find it whether it was in 1 or 2)

Here’s my model so far: (note Country1/2 can be multiple words)

class Project < ActiveRecord::Base
  mapping do
    indexes :id
    indexes :title, :boost => 100
    indexes :subtitle
    indexes :country1, :type => 'string', :index => 'not_analyzed'
    indexes :country2, :type => 'string', :index => 'not_analyzed'
  end
  def self.search(params)
    tire.search(load: true, page: params[:page], per_page: 10) do
    query do
      boolean do
        must { string params[:query], default_operator: "AND" } if params[:query].present?
        must { term :country1, params[:country] } if params[:country].present?
      end
    end
    sort { by :display_type, "desc" }
    facet "country" do
      terms :country1
    end

  end
end

Any tips greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:44:03+00:00Added an answer on June 8, 2026 at 7:44 am

    This commit https://github.com/karmi/tire/commit/730813f in Tire brings support for aggregating over multiple fields in the “terms” facet.

    The interface is:

    Tire.search('articles-test') do
      query { string 'foo' }
      # Pass fields as an array, not string
      facet('multi') { terms ['bar', 'baz'] }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some PDF attachments being indexed in Elasticsearch, using the Tire gem. It's
I want to index pdf attachment using Tire gem as client for ElasticSearch. In
Do you have any suggestions how to perform authorization of elasticsearch results (using tire)
I am using tire-0.4.2 to interact with elasticsearch in my rails application (uses mongodb
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I have been experimenting with elasticsearch lately with ruby on rails. I am having
I have crawled some data using nutch and managed to inject it into elasticsearch.
I am using Tire in ruby on rails to connect with ElastiSearch. When I
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I have some customer documents that I want to be retrieved using ElasticSearch based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.