Comments (10)
Hmm, this is weird. Also, it doesn't have any connection to "round robin", since the clients are separate, it's not the same instance.
So, I have generated a fresh Rails app with the template, and added two models:
# article.rb
#
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
__elasticsearch__.client.transport.logger = Logger.new(STDERR)
end
# book.rb
#
class Book < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
__elasticsearch__.client = Elasticsearch::Client.new host: 'localhost:9250'
__elasticsearch__.client.transport.logger = Logger.new(STDERR)
end
Now, I've started a separate cluster elasticsearch --cluster.name=books --node-name=book1 --http.port=9250
and when I run bundle exec rails console
:
>> Article.__elasticsearch__.create_index!
F, [2014-03-17T11:36:59.417716 #49843] FATAL -- : [404]
I, [2014-03-17T11:36:59.548716 #49843] INFO -- : PUT http://localhost:9200/articles [status:200, request:0.128s, query:n/a]
=> {"acknowledged"=>true}
>> Book.__elasticsearch__.create_index!
F, [2014-03-17T11:37:05.342066 #49843] FATAL -- : [404]
I, [2014-03-17T11:37:06.609309 #49843] INFO -- : PUT http://localhost:9250/books [status:200, request:1.267s, query:n/a]
=> {"acknowledged"=>true}
So each model talks to a different ES cluster. How are you configuring the models?
from elasticsearch-rails.
In config/initializers/loader.rb I do this:
(1) to cover most models:
Elasticsearch::Model.client = Elasticsearch::Client.new(host: 'localhost:9200')
(2) for the remote cluster model:
Share.__elasticsearch__.client = Elasticsearch::Client.new(host: "1.2.3.4:9500")
Is "(1)" causing the round robin ?
Should I move "(2)" into the model and out of the initializer ?
As the Share (remote cluster) model requires a template to be present (or put there),
it seemed like an initializer was the best location for that code.
It is strange ... and for several records it goes to the correct cluster, but then some
will go to the local cluster.
Also, when I do ".transport.inspect" I can see both IP's and port's in the output, and
the output is rather lengthly ... is there a way to just display the IP/port that the
client is using ?
I do love the gem, it's great, and I'm probably doing something wrong here.
from elasticsearch-rails.
So, first let me summarize what I have on my part.
In the config/initializers/elasticsearch.rb
I have:
Elasticsearch::Model.client = Elasticsearch::Client.new(host: 'localhost:9200')
Elasticsearch::Model.client.transport.logger = Logger.new(STDERR)
Book.__elasticsearch__.client = Elasticsearch::Client.new host: 'localhost:9250'
Book.__elasticsearch__.client.transport.logger = Logger.new(STDERR)
And when I run this in rails console
:
>> Article.__elasticsearch__.create_index!
I, [2014-03-17T17:06:06.097307 #52199] INFO -- : HEAD http://localhost:9200/articles [status:200, request:0.031s, query:n/a]
D, [2014-03-17T17:06:06.097670 #52199] DEBUG -- : <
=> nil
>> Book.__elasticsearch__.create_index!
I, [2014-03-17T17:06:09.030384 #52199] INFO -- : HEAD http://localhost:9250/books [status:200, request:0.009s, query:n/a]
D, [2014-03-17T17:06:09.030477 #52199] DEBUG -- : <
=> nil
>> Article.__elasticsearch__.client.transport.connections.map(&:host)
=> [{:host=>"localhost", :port=>"9200", :protocol=>"http"}]
>> Book.__elasticsearch__.client.transport.connections.map(&:host)
=> [{:host=>"localhost", :port=>"9250", :protocol=>"http"}]
from elasticsearch-rails.
To adress the other issues:
- The round robin rotation across nodes is only happenning when you a) actively pass the nodes to the client, b) tell it to "sniff" them from Nodes Info API
- I assume
localhost:9200
and1.2.3.4:9500
not running as part of the same cluster? Since I cannot guess the reason why you'd like to talk to a specific node within a cluster, for this model.
So, something is definitely mixed up here. Can you generate a Rails app with the linked template, add the second model, the initializer, and try it out? So we can start isolating the issue?
from elasticsearch-rails.
Hmm, that's exactly what I have in the initializer.
My issue isn't only creating the index, but as records are created in the database and
mirrored into the elasticsearch index some of them are indexed into the local
cluster and some of them are indexed into the remote cluster. As this rails app was an existing app that I'm converting to using elasticsearch, I did not start by using the rails app template.
No, localhost:9200 and 1.2.3.4:9500 are not a part of the same cluster. The reason one model
needs to use a different cluster (1.2.3.4:9500, not it's real IP) is to allow users to share certain
objects with each other. Basically the remote cluster at 1.2.3.4:9500 is a central location to
hold all share objects, so other installed instances of the same rails app can see the shares.
I hope my explanation is clear and helpful. I will experiment some more and get back to you,
and if the problem persists I will create an example rails app to emulate the issue.
from elasticsearch-rails.
Thanks for the explanation, all understood on the separate nodes now.
The client
should be definitely separated, no mixup between them. Try to generate the app with two models, and replicate what you're doing there, so we get an isolated, shared environment.
from elasticsearch-rails.
I left the initializer as is, but putting this into the Share (remote) model:
__elasticsearch__.client = Elasticsearch::Client.new(host: "1.2.3.4:9500")
after:
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name "#{APP_CONFIG[:host]}_shares"
document_type "share"
... seems to fix the issue and all records for the Share model go to the remote cluster.
It's just odd to specify the client connection info again in the model when it's already in
the initializer.
Thanks ... the gem is great, plus having the "as_indexed_json" method in the model
is very helpful.
from elasticsearch-rails.
Hmm, really, you shouldn't need to do that -- placing it into the initializer should have the same effect, I verified it with the example I posted...
from elasticsearch-rails.
I'm happy it's working :-) You're example just verified an index was created on the correct cluster, but within an app where a user can "bounce" around between different models while adding/updating/deleting records ... I'm not sure but perhaps that makes a difference somehow ... not a very well tested or scientific answer. If I notice the behavior again I will open an issue.
Thanks again for your prompt and helpful responses.
from elasticsearch-rails.
Great, open a new issue if you encounter further issues!
from elasticsearch-rails.
Related Issues (20)
- NPE happens on short prefix query on a field with index_prefixes
- Indexes are not refreshing, even with refresh_interval being set
- Disable automatic callbacks in rspec
- Not getting any records from elasticsearch HOT 1
- FYI gem version 6.1.1 was pushed without any changes HOT 1
- elasticsearch-model 7.2.1 introduces circular dependency with ruby 2.7 and rubygems 3.2.5 HOT 1
- specify an alias near the index_name in an AR model HOT 1
- Illegal argument "type" sent in all requests upgrading to 8.x HOT 1
- Not able to update single record too please help me to here HOT 1
- How to import into two clusters
- Mapping Two Ruby on Rails Models with Different Attribute Names to a Shared Elasticsearch Index using 'elasticsearch-rails'
- update_document not selective enough
- Backward compatibility for older Elasticsearch version HOT 1
- Faraday::ConnectionFailed (end of file reached) HOT 1
- Elasticsearch - Unexpected Character Error (Minus Sign) HOT 1
- Unexpected behavior when searching from a scope
- Feature Suggestion - Get Indexed Document for Instance
- Deprecation warning in Rails 7.1 (support Rails 7.2) HOT 2
- ElasticSearch::Model does not register a subclass HOT 3
- rake elasticsearch:import:model - ArgumentError: unknown keyword: :type (ArgumentError)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-rails.