-
Notifications
You must be signed in to change notification settings - Fork 803
Index name is being set on repository class not instance #811
Copy link
Copy link
Closed
Description
Hey, I've found out some weird behaviour, want to clarify I'm using the gem correctly. Here is the repository I have -
class UserRepository
include Elasticsearch::Persistence::Repository
klass User
def initialize index_name: nil;
type TYPE
client Elasticsearch::Client.new url: Figaro.env.elasticsearch_url!, log: configatron.elasticsearch.log
index index_name || DEFAULT_INDEX_NAME
create_index! unless index_exists?
end
endNow I want to write to a specific index using this repository. So I create a repository and provide an index name in arguments
> default_index_repo = UserRepository.new
> default_index_repo.index
=> "development_users"
> custom_index_repo = UserRepository.new(index_name: 'custom_index_name')
> custom_index_repo.index
=> "custom_index_name"Everything seems fine so far. But then I try following code
> default_index_repo.index
=> "custom_index_name"
> UserRepository.index
=> "custom_index_name"Now all repositories that I created before are pointing to a different index. This is something I didn't expect. Is this behaviour designed?
The problem is that I run such code in multithreaded environment(puma) and I need to create repositories that work with different indices. But when I create two repositories with different indices in different threads I have no idea what index they will actually use. Can someone advice?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.