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

Ordering doesn't work without RoR shutdown #990

Open
Zeben opened this issue Aug 10, 2016 · 1 comment
Open

Ordering doesn't work without RoR shutdown #990

Zeben opened this issue Aug 10, 2016 · 1 comment

Comments

@Zeben
Copy link

Zeben commented Aug 10, 2016

Sup. I deal with the problem for three days.
In my project where I use search in model Record I've implemented two buttons: "Delete index" and "Refresh index".
First button is redirecting page to controller delete_index where I execute Record.tire.index.delete.
Second button is redirecting page to controller refresh_index where the index is refreshing via Sidekiq worker, where I execute Record.import.
Main problem:
When I press "Delete index" - it works correct;
When I press "Refresh index" - the index is imports correctly but order by date is fully broken.
I've attached some screenshots with the problem.
Screenshot without problem: order is working:
image

Screenshot with problem: order is broken after I pressed "Delete index" and "Refresh index":
image

I can fix second case only if I do actions in this sequence:

  1. Execute Record.tire.index.delete
  2. Shutdown RoR server
  3. Execute RoR server with rails s
  4. Execure Record.import

Some piece of code:
records_controller.rb:

def refresh_index
  if params[:refresh]
    RecordsImport.perform_async('exec')
    redirect_to "/search"
  end
end
def delete_index
  if params[:delete]
    Record.tire.index.delete
    redirect_to "/search"
  end
end

records_import.rb:

class RecordsImport
  include Sidekiq::Worker
  def perform(name)
    if name == 'exec'
      Record.import
    else
      return
    end
  end
end

My mapping in record.rb model:

tire do
  mapping do
    indexes :id, index: :not_analyzed
    indexes :timestamp, type: 'date', format: 'dd.MM.yyyy HH:mm', include_in_all: false
    indexes :title, analyzer: 'snowball'
  end
end

My search query:

@records = Record.search page: params[:page], per_page: 50 do
  query do
    string: "*"
  end
  sort do
    by :timestamp, order: "desc"
  end
end

Maybe I'm doing something wrong, but all suggestions welcome. Thanks in advance and sorry for my bad English.

@karmi
Copy link
Owner

karmi commented Aug 17, 2016

Hi, this repository is no longer actively maintained, I suggest you have a look at the https://github.com/elastic/elasticsearch-ruby and https://github.com/elastic/elasticsearch-rails gems.

One piece of advice with any of the gems: you need to make sure that the index is created with the correct mapping, the new gems have the force option for that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants