tomekfranek
tomekfranek

Reputation: 7109

How to boost query depends of attribute's value in ElasticSearch?

I have a Profile class. In ES index I have company_type attribute.

class Profile
  ...
  include Tire::Model::Search
  include Tire::Model::Callbacks

  def to_indexed_json
    { name: self.name,
      company_type: self.company.company_type
    }.to_json
  end
end

Tire.search('profiles') do
  query do
    custom_filters_score do
      query { all }

      filter do
        filter :range, last_contact_at: { gte: 7.days.ago }
        boost 1
      end

      score_mode :total
    end
  end
end.results

I would like to boost by 10 queries if company_type == 'intern'.

Upvotes: 0

Views: 219

Answers (1)

phoet
phoet

Reputation: 18845

did you try adding

filter do
  filter :term, company_type: "intern"
  boost 10.0
end

to your custom_filters_score filter?

Upvotes: 1

Related Questions