I have been looking for a while and could not find information about how to create a Ruby on Rails application that uses just ElasticSearch as a backend.
Can anyone show me the way to use the ElasticSearch gems available to back a model in a ruby on rails application to only ElasticSearch?
All of the solutions I find involve backing data to a relational database like MySQL and then updating ElasticSearch on callbacks/hooks. I was trying to avoid having the data in two places, would like all data to live in ElasticSearch.
I envisions something like this:
class Person < ElasticSearch::ActiveRecord::Base
end
Where ElasticSearch::ActiveRecord::Base will back the model to ElasticSearch.
Related
Is it possible to use Elasticsearch as database for a Rails Application?
I have gone through many sites, blogs, and videos to find the answer of this, but was unable to and this being the closest.
I am not sure how can it be done, what goes in the database/config.yml and will the schema be getting generated after migrate?
Yes, of course it is, but you cannot use ActiveRecord ORM, basically you'll have to create your own adapter.
If you want to go quick, I would advise you to create the activerecord models, just like any regular app, then use Searchkick and create mappings from your models.
You need to be aware that if you're not using a database to hold the values you'll need to create a repository to handle the CRUD operations in Elasticsearch.
Another option is to use https://github.com/elastic/elasticsearch-rails, but in both cases you need to have the Rails models.
If you really want to go for ElasticSearch only, in you controllers you need to call your own created repositories to fetch and save the records in ElasticSearch.
No, only these databases: MySQL, PostgreSQL, SQLite are supported if you want to use ActiveRecord, and there are also mappers for Mongo and the like.
There are some mappers and adapters out there though but I wouldn't touch them with a 10 foot barge pole - some things just shouldn't exist in this world.
Is it possible to use multiple couchdb databases for data in rails app while using the CouchRest Model gem? Right now in my rails app I specify the one couchDB database in config/couchdb.yml. I was wondering if it possible to have more than one couchdb databases being used by one rails app?
You might want to check out this answer - it worked for my case where I wanted a database for each user
Recommended use of couchrest model in a multi-tenant app
My Rails app runs primarily on a regular mySQL database, however, if this database goes down I would like the Rails app to failover to a MongoDB database which is basically just a 'cached' version of the primary database.
Some ideas I had were two models (AR and MongoDB - using Mongoid) and then catching exceptions in the controllers and using the MongoDB models if the primary fails, but I feel like that would be too cluttered having two models of everything. Another idea was (and I haven't tested) rescuing database connection exceptions in the model and using the model as a MongoDB one instead but thinking about it, if the model originally inherits from ActiveRecord::Base there might be issues.
What would be a good approach to tackle this?
I don't think there is any good way to have a failover between MySQL and MongoDB, and to be honest I'm not too fond of the idea.
Why not make your MySQL Backend failsave with a few slaves?
I'm currently using SQLite3 with a simple post and image sharing app, similar to the Rails 3 Hartl tutorial (in terms of db structure). But I'd like to move to Mongo for future scalability/learning.
I'm also hosted on Heroku, and am using a 15 GB shared db. I attempted to install MongoHQ and MongoMapper (as per Heroku's instructions) for the transition and this part according to Heroku's support is set up correctly. However, when I turn off the shared db, the app stops working, rather than running off of Mongo.
I'm not sure what do do next, do I have to rewrite my code in mongo or does mongo mapper solve all that? Do I lose my data if I change, if so, how do I copy?
Could any of you please point me to some resources or help me out? Thank you very much!!
MongoDB is not a drop in replacement for a SQL database. There are a couple of things you need to adapt:
The models' code are to be updated to use MongoDB. I can suggest using Mongoid, an ODM, as it will ease your learning path. Mongoid implements Active Record.
The current data saved in your SQL database needs to be migrated - and this is not automatic – to MongoDB schemas. MongoDB do not support migrations as you are used to in SQL world. You will need to write your own scripts for that.
I suggest you write a simple app from scratch using your MongoDB ODM of choice – MongoMapper or Mongoid – so that you get familiar with the basis of MongoDB before attempting to make a migration.
We are using a dynamic attributes plugin similar to this:
http://codaset.com/joelmoss/dynamic-attributes
Which allows us to store dynamic attributes in our rails model. Those dynamic attributes are in a single database column. We are facing performance issues because of this and I am wondering if MongoId, MongoMapper or other rails plugins will allow us to keep some attribute in ActiveRecord (keeping the < ActiveRecord::Base) but store the dynamic attributes in mongodb. We want to do this because we need to keep using MySQL for most of our existing system, but use MongoDB to store dynamic attributes about some models.
Basically this is what I am talking about:
http://www.railsinside.com/plugins/242-quickly-add-couchdb-to-existing-rails-models-with-stuffing.html
This plugin does the exact same thing using CouchDB.
I don't see any reason that MongoDB can't handle the same thing.
MongoMapper should implement the ActiveRecord pattern. However, Mongo also has some simple drivers for Ruby. All in all, the concept of storing dynamic attributes is a perfect use-case for MongoDB.
If you don't mind skipping "ActiveRecord" you can probably cook up your own using the basic Mongo drivers with very little work.
If you can't figure out the steps to do this, I would suggest pinging the groups (http://groups.google.com/mongodb-user/) and asking Kyle Banker directly (he's their ruby expert).