ankane/searchkick

Routing not working

antarr opened this issue · 3 comments

I'm using searckick (5.2.4) to search through a set of voter data. I need to be able to filter it based on a given state, i.e, CA or TX. I'm using the routing API provided but getting TX records when trying to get CA records.

query

VoterRecord.search("*", limit: 10, routing: 'CA').results

app/models/voter_record.rb

class VoterRecord < ApplicationRecord
  # include PgSearchable

  self.implicit_order_column = 'id'

  searchkick word_start: %i[address_line_1 address_line_2], callbacks: :async, batch_size: 1000, routing: true

  def search_data
    {
      address_line_1: address_line_1,
      address_line_2: address_line_2,
      city: city,
      state: state.abbr,
      zip: zip
    }
  end

  def search_routing
    state_abbr
  end

Hi @antarr, you'll need to specify the where option as well to only get results for a specific state (the shard the query is routed to can contain multiple states).

@ankane Just tried that and it came back with no matches

VoterRecord.search("*", where: {state_abbr: 'CA'})
=> #<Searchkick::Relation []>

also tried combining

VoterRecord.search("*", where: {state_abbr: 'CA'}, routing: 'CA')

The field is indexed as state in the code above.