-
Notifications
You must be signed in to change notification settings - Fork 801
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
Support inherited index names and doc types #332
Conversation
My local build failed too when I tried to run the full test suite. Is master not passing?
|
CLA should be signed now. |
Hello Ryan, thanks for the patch and sorry for such an embarrasing delay! This has slipped me -- I'll find some time to review it in the coming days. Please do ping me if I slip again! |
Don't know where to put my two words about STI problem. Your PR should help with this excluding situation when it's needed to keep type while importing. But in that situation it is possible to use different |
@gsmetal it looks like that's the result of the batch-based import process: One option is to eager load the project and then use |
I think something like this is better and works well |
I haven't used transforms yet but yes, that does look like a much easier solution. And that will still take advantage of the existing batch import process? |
Still haven't found time to properly review the approach and the code... Please ping me if I slip again, @rymohr! |
@Tonkpils nope, I ended up using this as a placeholder for now: module Search::InheritedIndexing
extend ActiveSupport::Concern
included do
index_name superclass.index_name
document_type superclass.document_type
end
end
# ...
class Api::Project < Project
include Search::InheritedIndexing
# ...
end Not sure if it makes more sense to walk the ancestors as I've done or just use |
As far as Ideally, I'd like to avoid having to include a module on each child class as on big codebases there can be many instances. |
@Tonkpils yeah, with my approach in the PR you would just opt into the inheritance. You wouldn't include anything in the subclasses. That's just a workaround for the existing behavior. Elasticsearch::Model.inheritance_enabled = true |
👍 |
Hello, is someone found a workaround for this topic or are you planning to fix this patch? |
Ping |
Is there any progress on that PR? Would be really useful! |
+1 |
Hi, I've finally merged the patch. Many thanks for the contribution, @rymohr! I've added a UPDATE: And sincere thanks to all bumping the issue with their comments. They do help! :) |
I am having an issue using this is Mongoid. On line 80 of model/naming.rb, self is a Elasticsearch::Model::Proxy::ClassMethodsProxy which creates an endless loop. Still working on figuring out what's up. |
Fixed it by changing line model/naming.rb:80 to next if klass == self || self.respond_to?(:target) && klass == self.target I don't know enough about the codebase to know why that is being called as a proxy, nor how I could test for that. |
this PR seem like problemable for me, I use Rails 5.0.0, When I add following config to my project. Gemfile 1576124 gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'
gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git' models/goods_item.rb, this file is base class for others. require 'elasticsearch/model'
class GoodsItem < ApplicationRecord
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name 'goods_items'
document_type 'goods_items'
....
GoodsItem.import config/initilaizer/es.rb Elasticsearch::Model.settings[:inheritance_enabled] = true This will result in following error: SystemStackError: stack level too deep |
If comment following code: # Elasticsearch::Model.settings[:inheritance_enabled] = true
Api::V1::GoodsItemsControllerTest#test_#update:
Elasticsearch::Transport::Transport::Errors::NotFound: [404] {"error":{"root_cause":[{"type":"document_missing_exception","reason":"[free_goods_item][1331029462092192769]: document missing","shard":"0","index":"free_goods_items"}],"type":"document_missing_exception","reason":"[free_goods_item][1331029462092192769]: document missing","shard":"0","index":"free_goods_items"},"status":404} |
I've the same issue as @kayakyakr (ActiveRecord though) and arrived at exactly the same fix (should have read the comments more carefully). I'd submit a PR but I'm afraid I can't get the test suite to run 😬 @rymohr does @kayakyakr's proposal look reasonable? |
This PR adds support for inheriting
index_name
anddocument_type
on an opt-in basis:We wrap all our models exposed through our api in an
Api::
wrapper that helps us handle versioning issues. Without support for inherited values it's easy to forget to add the explicit values to the subclasses, or update them if the base class ever changed.Related to #28 and #92. Not sure it's enough for #170.