Skip to content

Is it possible to automatically set the parent for routing? #109

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
AaronRustad opened this issue May 8, 2014 · 8 comments
Closed

Is it possible to automatically set the parent for routing? #109

AaronRustad opened this issue May 8, 2014 · 8 comments

Comments

@AaronRustad
Copy link
Contributor

Currently, is it only possible to set the parent on a document via callbacks as suggested in the Parent/Child Example?

I would think that the library should be able identify a parent_id and set it if possible... perhaps something like:

class Article
__elasticsearch__.parent_id :author_id
## OR ##
__elasticsearch__.parent :author
end

If there is already way to do it other than overriding the callbacks, please let me know. If no, if you have thoughts how how it should work, I'd be willing to take a stab at coding up that functionality.

I guess this also would extend into importing as well.

@karmi
Copy link
Contributor

karmi commented May 8, 2014

I wouldn't do it like that... Why have some kind of "DSL" for a thing like this...

By the way, I wonder if I do something wrong in the message, because the README says quite emphatically: “In case you would need more control of the indexing process, you can implement these callbacks yourself, by hooking into after_create, after_save, after_update or after_destroy operations”.

What's the problem with defining your own callbacks? Why would the "automatic callbacks" be so smart they handle all potential cases?

I'm asking because this came up in #108 as well, and I honestly don't know how to message this in a better and more clear way.

@AaronRustad
Copy link
Contributor Author

I suppose I looked at __elasticsearch__#.index_name and asked myself a similar question. I'm not opposed to writing the custom callbacks if necessary and that is the chosen design of the API.

I don't believe overriding the callbacks will set the the parent on bulk imports though, will it?

@AaronRustad
Copy link
Contributor Author

With regard to the documentation, perhaps it's not explicit enough.

Automatic Callbacks

You can automatically update the index whenever the record changes ...
Could be? ...
As a matter of convenience, you can can automatically update the index ... Please note, the current approach to customizing indexing is by writing your own callbacks.

@karmi
Copy link
Contributor

karmi commented May 8, 2014

@AaronRustad Yeah, I mean the very next header... (Custom Callbacks)

@karmi
Copy link
Contributor

karmi commented May 8, 2014

I don't believe overriding the callbacks will set the the parent on bulk imports though, will it?

No, that again must be customised, and I think there should be a nice a way to manipulate the JSON being sent during _bulk.

@AaronRustad
Copy link
Contributor Author

Hi @karmi,

I spent some time this afternoon looking at a possible solution for importing records and assigning the parent. Let me know what you think of this:

https://github.com/AaronRustad/elasticsearch-rails/compare/set_parent_id_for_import

I believe it's along the lines of what you're thinking.


(UPDATE by @karmi: Changed the link to the Git compare view)

@karmi
Copy link
Contributor

karmi commented May 9, 2014

@AaronRustad It's a "consistent" solution to the problem, in line with eg. the SCOPE added earlier, but it has one big downside -- it's specific to solving this particular parent/child problem.

So, when somebody else has another requirement, what should we do, add another environment variable?

A much more generic solution, allowing everybody to customize/change the serialization of individual records, would be to pass a block to the import method, like Tire did in its time:

    Tire.index 'articles' do
      import articles do |documents|

        documents.each { |document| document[:title].capitalize! }
      end

      refresh
    end

The trouble, of course, is that the import method already accepts the block, which is then used to access response corresponding to each batch. So we would need to pass this block as an option?

@AaronRustad
Copy link
Contributor Author

I'm closing this issue. I submitted Pull Request #113 which satisfies my original question and allows future expansion of additional import capabilities.

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