Skip to content
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

Elasticsearch::Client unexpectedly modifies parameters during search #1727

Closed
j-bennet opened this issue Mar 19, 2022 · 4 comments
Closed

Elasticsearch::Client unexpectedly modifies parameters during search #1727

j-bennet opened this issue Mar 19, 2022 · 4 comments

Comments

@j-bennet
Copy link

When calling search method of Elasticsearch::Client and passing in a dict of parameters, parameters are unexpectedly modified. Here is a minimal example:

require 'elasticsearch'
require 'awesome_print'

class MyQueueSearch
  attr_accessor :index
  attr_accessor :client

  def initialize
    self.index = 'my_test_index'
    self.client = Elasticsearch::Client.new(:user => 'elastic', :password => 'changeme')
  end

  def search
    search_args = {
      :index => self.index,
        :body => {
          :_source => false,
            :seq_no_primary_term => true,
              :query => {
                :bool => {
                  :filter => {
                    :term => {
                      :status => 'pending'
                    }
            }
          }
        }
      }
    }

    puts("Search args before:")
    ap(search_args)
    res = self.client.search(search_args)
    puts('-' * 40)
    puts("Search args after:")
    ap(search_args)
  end

  def create_index
    self.client.indices.delete(:index => self.index, :ignore_unavailable => true)
    self.client.indices.create(:index => self.index)
    self.client.index(:index => self.index, :id => "1", :body => {'status' => 'pending'})
  end

  def run
    create_index
    search
  end
end

s = MyQueueSearch.new
s.run

Output:

Search args before:
{
    :index => "my_test_index",
     :body => {
                    :_source => false,
        :seq_no_primary_term => true,
                      :query => {
            :bool => {
                :filter => {
                    :term => {
                        :status => "pending"
                    }
                }
            }
        }
    }
}
----------------------------------------
Search args after:
{
    :index => "my_test_index"
}

If I needed my params after, this is breaking behavior.

The behavior changed between 7.17 and 8.0.

@picandocodigo
Copy link
Member

Hi @j-bennet,
I see why this is happening, it's a bug I introduced in 8.x. I'll write a fix and backport it to 8.0 and 8.1 so it'll be available in the next patch releases.
Thanks!

picandocodigo added a commit that referenced this issue Mar 24, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 24, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 24, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 29, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 29, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 29, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Mar 29, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
picandocodigo added a commit that referenced this issue Apr 4, 2022
When updating the code generator for 8.x, the order of
`arguments.clone` in the generated code was changed. This would make
it so that we would modify the arguments before cloning them, which is
undesired.

Addresses #1727
@picandocodigo
Copy link
Member

@j-bennet this is now fixed in 8.1.2 and 8.0.1. Let me know if there are any further issues. Thanks!

@picandocodigo
Copy link
Member

@j-bennet have you had a chance to test the latest releases? Is it ok to close this issue now?

@j-bennet
Copy link
Author

Yes, this seems to be fixed. Thank you!

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

No branches or pull requests

2 participants