Comments (5)
Yeah, or something totally simple like:
# config/initializers/elasticsearch.rb
MyApp::Client = Elasticsearch::Client.new url: ENV["ELASTICSEARCH_URL"]
Then in eg. controller:
MyApp::Client.search ...
from elasticsearch-ruby.
Something like this should work:
# /lib/elasticsearch.rb
module YourAppName
module Elasticsearch
extend self
attr_accessor :config
# @return [Elasticsearch::Transport::Client]
def client
@client ||= ::Elasticsearch::Client.new(config.to_h)
end
end
end
# /config/initializers/elasticsearch.rb
YourAppName::Elasticsearch.config = {
:hosts => ["search.myserver.com"]
}
# some_file.rb
YourAppName::Elasticsearch.client.search body: { :query => { :match_all => {} } }
from elasticsearch-ruby.
Heh, much simpler ^^
from elasticsearch-ruby.
Thank you both. That's very helpful. I will revise my initializer accordingly.
Not to keep this thread going on forever, but do either of you have experience with hosted elasticsearch solutions? I've looked at all the major providers, but it almost seems easy enough to just set up an ec2 instance with elasticsearch on my own.
Any thoughts or recommendations are much appreciated!
from elasticsearch-ruby.
@JeffLocke Sorry, missed your last comment -- no experience, but I think you can just test them all, compare prices, etc. Found.no look like a knowledgeable bunch of fellows :)
from elasticsearch-ruby.
Related Issues (20)
- Elasticsearch::Client#open_point_in_time returns NoMethodError HOT 2
- elasticsearch-ruby 7.14 silently dropping support for elastic search 5.x HOT 2
- Elasticsearch 6 on Mac is not running HOT 1
- Adding tracing? HOT 6
- Stuck on loop because the number of connections keeps increasing
- Elasticsearch server validation is incompatible with some builds HOT 5
- unlock/upgrade faraday dependency HOT 3
- Version change of behaviour on scroll endpoint HOT 2
- setting an api key in the client constructor clobbers whatever transport options you're trying to send in HOT 1
- Elasticsearch ruby errors in rails boot when more than 1 http client available HOT 2
- Version 7 to 8 compatibility HOT 2
- Add possibility to ignore 404 for clear_scroll API request HOT 1
- How call put_lifecycle method HOT 3
- version conflict error HOT 1
- Retry_on_conflicts implementation HOT 2
- Enable elasticsearch-transport v7 to use Faraday >=2 HOT 1
- Segfault when using elasticsearch within spring on MacOS 14.1.1 HOT 4
- Feedback 🗣️
- Elasticsearch Client Version Mismatch and Argument Error After Gem Upgrade HOT 6
- end of file reached (Faraday::ConnectionFailed) HOT 4
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-ruby.