Skip to content

Indexer example fails on ES 7+ #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dixpac opened this issue Dec 6, 2020 · 1 comment
Open

Indexer example fails on ES 7+ #967

dixpac opened this issue Dec 6, 2020 · 1 comment
Labels

Comments

@dixpac
Copy link

dixpac commented Dec 6, 2020

Indexer example:

class Indexer
  include Sidekiq::Worker
  sidekiq_options queue: 'elasticsearch', retry: false

  Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
  Client = Elasticsearch::Client.new host: 'localhost:9200', logger: Logger

  def perform(operation, record_id)
    logger.debug [operation, "ID: #{record_id}"]

    case operation.to_s
      when /index/
        record = Article.find(record_id)
        Client.index  index: 'articles', type: 'article', id: record.id, body: record.__elasticsearch__.as_indexed_json
      when /delete/
        begin
          Client.delete index: 'articles', type: 'article', id: record_id
        rescue Elasticsearch::Transport::Transport::Errors::NotFound
          logger.debug "Article not found, ID: #{record_id}"
        end
      else raise ArgumentError, "Unknown operation '#{operation}'"
    end
  end
end

Doesn't work for me on ES 7. When I change the type from article -> _doc then it works:

Client.index  index: 'articles', type: '_doc', id: record.id, body: record.__elasticsearch__.as_indexed_json

#or 
Client.index  index: 'articles' id: record.id, body: record.__elasticsearch__.as_indexed_json

Maybe I'm doing something wrong or this is expected change but didn't yet get into README since 7 branch is still not released. I'm just posting it here so maybe it can help someone.

@dixpac
Copy link
Author

dixpac commented Dec 6, 2020

Opened a PR maybe doesn't make a sense 😅

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

No branches or pull requests

2 participants