toptal / chewy

High-level Elasticsearch Ruby framework based on the official elasticsearch-ruby client
MIT License
1.88k stars 364 forks source link

Per-query client configuation adjustments. #959

Open andriytyurnikov opened 1 month ago

andriytyurnikov commented 1 month ago

Per-call client configuation adjustments.

When many queries are invoked in many parts of an app, it seems challenging to have a customised value of request_timeout per query, as client instance is set on first invocation in a thread.

Ability to override client parameters per query call seems like a straightforward solution

Additional context

    # Main elasticsearch-ruby client instance
    #
    def client
      Thread.current[:chewy_client] ||= begin
        client_configuration = configuration.deep_dup
        client_configuration.delete(:prefix) # used by Chewy, not relevant to Elasticsearch::Client
        block = client_configuration[:transport_options].try(:delete, :proc)
        ::Elasticsearch::Client.new(client_configuration, &block)
      end
    end