Skip to content
New issue

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

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

Already on GitHub? # to your account

Pass a block to Elasticsearch::Client #296

Closed
davekaro opened this issue Dec 9, 2015 · 1 comment
Closed

Pass a block to Elasticsearch::Client #296

davekaro opened this issue Dec 9, 2015 · 1 comment

Comments

@davekaro
Copy link
Contributor

davekaro commented Dec 9, 2015

I'd like to pass a block to configure the faraday instance of the Elasticsearch::Client. From elasticsearch-transport readme:

You can use any standard Faraday middleware and plugins in the configuration block, for example sign the requests for the AWS Elasticsearch service:

require 'patron'
require 'faraday_middleware/aws_signers_v4'

client = Elasticsearch::Client.new url: 'https://search-my-cluster-abc123....es.amazonaws.com' do |f|
  f.request :aws_signers_v4,
            credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_ACCESS_KEY']),
            service_name: 'es',
            region: 'us-east-1'
end

I believe https://github.com/toptal/chewy/blob/master/lib/chewy.rb#L125 is where the client is created, but I'm not sure the best way to pass a block to that. Could I simply override the client myself by setting Thread.current[:chewy_client] to whatever I want? Are there multi-threaded concerns I should be aware of if I do that?

@pyromaniac
Copy link
Contributor

Well, I would rather redefine the whole method in my application, also I would (if I would be on your place) create a patch since this is a good observation :)

This was referenced Dec 17, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants