Skip to content

Questions about the create_index! method #919

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

Closed
shunta27 opened this issue Jan 23, 2020 · 2 comments
Closed

Questions about the create_index! method #919

shunta27 opened this issue Jan 23, 2020 · 2 comments

Comments

@shunta27
Copy link

When you execute the instance method of the repository class that includes the "Elasticsearch :: Persistence :: Repository" module. create_index! (Index: 'test_index'), nil is returned. Which is this a bug or my bad use?

@oriahu
Copy link

oriahu commented Mar 23, 2020

I have a question that might follow on from this one.

Should we expect indexing ClassMethods to continue to work on a Repository class, as class methods? They seem to work just fine as instance methods because they are included directly into the repository.

Some Context

Noticed this in the DSL module:

        def self.included(base)
          base.send(:extend, Elasticsearch::Model::Indexing::ClassMethods)
          base.send(:extend, ClassMethods)
        end

When calling Repository.create_index!, i get the following error:

*** NotImplementedError Exception: The 'create_index!' method is not implemented on the Repository class.

When i checked the Repository ancestors noticed:

[ ..., Singleton, Elasticsearch::Persistence::Repository::DSL, Elasticsearch::Persistence::Repository, Elasticsearch::Model::Indexing::ClassMethods, ...]

It seems like the DSL module, when included, will override the Indexing ClassMethods set on the Respository class with it's own stubbed out and unimplemented class methods via: base.send(:extend, ClassMethods)

I think the fix could be to switch those two lines around in the self.included(base) method.

A workaround might be to just extend with the indexing class methods explicitly, ie where i include DSL, but actually haven't gotten this working yet 😅

    include Elasticsearch::Persistence::Repository::DSL
    extend Elasticsearch::Model::Indexing::ClassMethods

UPDATE

Just found the test i was looking for: here

Taking a look into this PR and related PRs to better understand the WHY.

@shunta27
Copy link
Author

Thank you.
Using the repository class, I was able to solve what I wanted to do.

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

No branches or pull requests

2 participants