https://github.com/elastic/elasticsearch-rails
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
https://github.com/elastic/elasticsearch-rails
Keywords
activemodel activerecord elastic elasticsearch rails ruby ruby-on-rails
Keywords from Contributors
mvc activejob rubygems rubynlp rubocop static-code-analysis code-formatter sidekiq background-jobs capistrano
Last synced: about 4 hours ago
JSON representation
Repository metadata
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
- Host: GitHub
- URL: https://github.com/elastic/elasticsearch-rails
- Owner: elastic
- License: apache-2.0
- Created: 2013-11-08T17:00:19.000Z (about 12 years ago)
- Default Branch: main
- Last Pushed: 2025-10-08T13:42:09.000Z (3 months ago)
- Last Synced: 2026-01-02T02:26:10.803Z (8 days ago)
- Topics: activemodel, activerecord, elastic, elasticsearch, rails, ruby, ruby-on-rails
- Language: Ruby
- Homepage:
- Size: 5.53 MB
- Stars: 3,082
- Watchers: 388
- Forks: 805
- Open Issues: 52
- Releases: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
README.md
Elasticsearch Rails
This repository contains various Ruby and Rails integrations for Elasticsearch:
- ActiveModel integration with adapters for ActiveRecord and Mongoid
- Repository pattern based persistence layer for Ruby objects
- Enumerable-based wrapper for search results
- ActiveRecord::Relation-based wrapper for returning search results as records
- Convenience model methods such as
search,mapping,import, etc - Rake tasks for importing the data
- Support for Kaminari and WillPaginate pagination
- Integration with Rails' instrumentation framework
- Templates for generating example Rails application
Elasticsearch client and Ruby API is provided by the
elasticsearch-ruby project.
Installation
Install each library from Rubygems:
gem install elasticsearch-model
gem install elasticsearch-rails
Compatibility
The libraries are compatible with Ruby 3.0 and higher.
We follow Ruby’s own maintenance policy and officially support all currently maintained versions per Ruby Maintenance Branches.
The version numbers follow the Elasticsearch major versions. Currently the main branch is compatible with version 8.x of the Elasticsearch stack.
| Rubygem | Elasticsearch | |
|---|---|---|
| 0.1 | → | 1.x |
| 2.x | → | 2.x |
| 5.x | → | 5.x |
| 6.x | → | 6.x |
| 7.x | → | 7.x |
| 8.x | → | 8.x |
| main | → | 8.x |
Check out Elastic product end of life dates to learn which releases are still actively supported and tested.
Usage
This project is split into three separate gems:
-
elasticsearch-model,
which contains search integration for Ruby/Rails models such as ActiveRecord::Base and Mongoid, -
elasticsearch-persistence,
which provides a standalone persistence layer for Ruby/Rails objects and models -
elasticsearch-rails,
which contains various features for Ruby on Rails applications
Example of a basic integration into an ActiveRecord-based model:
require 'elasticsearch/model'
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
# Index creation right at import time is not encouraged.
# Typically, you would call create_index! asynchronously (e.g. in a cron job)
# However, we are adding it here so that this usage example can run correctly.
Article.__elasticsearch__.create_index!
Article.import
@articles = Article.search('foobar').records
You can generate a simple Ruby on Rails application with a single command
(see the other available templates). You'll need to have an Elasticsearch cluster running on your system before generating the app. The easiest way of getting this set up is by running it with Docker with this command:
docker run \
--name elasticsearch-rails-searchapp \
--publish 9200:9200 \
--env "discovery.type=single-node" \
--env "cluster.name=elasticsearch-rails" \
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--rm \
docker.elastic.co/elasticsearch/elasticsearch:7.6.0
Once Elasticsearch is running, you can generate the simple app with this command:
rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/01-basic.rb
Example of using Elasticsearch as a repository for a Ruby domain object:
class Article
attr_accessor :title
end
require 'elasticsearch/persistence'
repository = Elasticsearch::Persistence::Repository.new
repository.save Article.new(title: 'Test')
# POST http://localhost:9200/repository/article
# => {"_index"=>"repository", "_id"=>"Ak75E0U9Q96T5Y999_39NA", ...}
Please refer to each library documentation for detailed information and examples.
Model
Persistence
Rails
Development
To work on the code, clone the repository and install all dependencies first:
git clone https://github.com/elastic/elasticsearch-rails.git
cd elasticsearch-rails/
bundle install
rake bundle:install
Running the Test Suite
You can run unit and integration tests for each sub-project by running the respective Rake tasks in their folders.
You can also unit, integration, or both tests for all sub-projects from the top-level directory:
rake test:all
The test suite expects an Elasticsearch cluster running on port 9250, and will delete all the data.
License
This software is licensed under the Apache 2 license, quoted below.
Licensed to Elasticsearch B.V. under one or more contributor
license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright
ownership. Elasticsearch B.V. licenses this file to you under
the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Owner metadata
- Name: elastic
- Login: elastic
- Email: info@elastic.co
- Kind: organization
- Description:
- Website: https://www.elastic.co/
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/6764390?v=4
- Repositories: 858
- Last ynced at: 2025-10-28T00:29:28.877Z
- Profile URL: https://github.com/elastic
GitHub Events
Total
- Issues event: 6
- Watch event: 25
- Delete event: 1
- Issue comment event: 14
- Push event: 16
- Pull request event: 8
- Fork event: 8
- Create event: 2
Last Year
- Issues event: 1
- Watch event: 16
- Delete event: 1
- Issue comment event: 9
- Push event: 16
- Pull request event: 8
- Fork event: 6
- Create event: 2
Committers metadata
Last synced: 1 day ago
Total Commits: 734
Total Committers: 113
Avg Commits per committer: 6.496
Development Distribution Score (DDS): 0.459
Commits in past year: 6
Committers in past year: 2
Avg Commits per committer in past year: 3.0
Development Distribution Score (DDS) in past year: 0.167
| Name | Commits | |
|---|---|---|
| Karel Minarik | k****k@e****m | 397 |
| Fernando Briano | f****o@p****t | 93 |
| Emily Stolfo | e****o@g****m | 88 |
| Miguel Fernandez | m****z@g****m | 12 |
| David Padilla | d****d@e****m | 6 |
| Ryan Schlesinger | r****n@i****m | 4 |
| Eric Bouchut | e****t@g****m | 4 |
| Andre Arko | a****e@a****t | 4 |
| Brian Alexander | b****d@g****m | 3 |
| Aaron Rustad | a****d@a****m | 3 |
| Colin MacKenzie IV | s****k@g****m | 3 |
| Bruno Michel | b****l@f****r | 3 |
| Takumasa Ochi | a****7@g****m | 3 |
| Sean Devine | b****n@i****m | 2 |
| Nigel Small | n****l@e****o | 2 |
| Jon Roberts | j****n@e****t | 2 |
| Tony Pitale | t****e@g****m | 2 |
| nipe | n****4@g****m | 2 |
| treby | t****y@a****t | 2 |
| Russell Jennings | v****r@g****m | 2 |
| JA | ja@j****g | 2 |
| Kelly Joseph Price | k****y@c****m | 2 |
| Kenta Suzuki | k****i@c****p | 2 |
| Savater Sebastien | s****n@g****m | 2 |
| Berislav Babic | b****o@g****m | 1 |
| Celso Dantas | c****s@g****m | 1 |
| Chris Yuska | c****a@g****m | 1 |
| Dong Wook Koo | d****g@h****e | 1 |
| Doug Tabuchi | D****g@D****m | 1 |
| Eduardo Turiño | e****o@a****m | 1 |
| and 83 more... | ||
Committer domains:
- detailedbalance.net: 1
- archlinux.us: 1
- me.com: 1
- gadget.consulting: 1
- dubinski.net: 1
- o2web.ca: 1
- siebert.org: 1
- koenpunt.nl: 1
- outlook.in: 1
- laststar.eu: 1
- lostapathy.com: 1
- thoughtbot.com: 1
- goodlife.tw: 1
- ohnoco.com: 1
- vhyza.eu: 1
- byu.net: 1
- eq8.eu: 1
- baucloud.com: 1
- schilling.io: 1
- tim-bleck.de: 1
- fastmail.fm: 1
- nilbus.com: 1
- mail.ru: 1
- emailaccount.com: 1
- lovemondays.com.br: 1
- jsdev.co: 1
- digitalkookie.io: 1
- ifttt.com: 1
- nypl.org: 1
- ayaya.tw: 1
- twobucks.co: 1
- hannesmoser.at: 1
- konklone.com: 1
- artirix.com: 1
- dougtabuchi.com: 1
- hirepurpo.se: 1
- crowdworks.co.jp: 1
- collaborativedrug.com: 1
- josealberto.org: 1
- atelier-nodoka.net: 1
- emptyflask.net: 1
- elastic.co: 1
- free.fr: 1
- anassina.com: 1
- arko.net: 1
- instanceinc.com: 1
- easybroker.com: 1
- picandocodigo.net: 1
- elasticsearch.com: 1
Issue and Pull Request metadata
Last synced: 28 days ago
Total issues: 76
Total pull requests: 82
Average time to close issues: about 1 year
Average time to close pull requests: 5 months
Total issue authors: 70
Total pull request authors: 41
Average comments per issue: 3.34
Average comments per pull request: 1.33
Merged pull request: 36
Bot issues: 0
Bot pull requests: 2
Past year issues: 4
Past year pull requests: 6
Past year average time to close issues: 10 days
Past year average time to close pull requests: about 1 hour
Past year issue authors: 4
Past year pull request authors: 4
Past year average comments per issue: 0.5
Past year average comments per pull request: 0.83
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- slhck (2)
- exocode (2)
- jonnynux (2)
- lazaronixon (2)
- vanboom (2)
- robmathews (2)
- RossBarnie (1)
- vamsipavanmahesh (1)
- scarrick68 (1)
- pravi (1)
- key88sf (1)
- Oshuma (1)
- sylvain-8422 (1)
- AaronRustad (1)
- Sexual (1)
Top Pull Request Authors
- picandocodigo (30)
- rafayqayyum (3)
- SeanLF (2)
- maciek-rr (2)
- martijnbolhuis (2)
- ivamuno (2)
- AZanellato (2)
- beatjoerg (2)
- sinisterchipmunk (2)
- martinstreicher (2)
- aeroastro (2)
- elastic-renovate-prod[bot] (2)
- aronwolf90 (1)
- jpr5 (1)
- ydah (1)
Top Issue Labels
- stale (12)
- pinned (12)
- bug (9)
- waiting (3)
- feature (2)
- fix (1)
- 6.x (1)
- waiting-for-user (1)
Top Pull Request Labels
- CI (4)
- pinned (3)
- documentation (3)
- release (3)
- 8.x (2)
- feature (1)
- 6.x (1)
- stale (1)
- fix (1)
- bug (1)
Package metadata
- Total packages: 5
-
Total downloads:
- rubygems: 128,129,057 total
- Total docker downloads: 868,406,076
- Total dependent packages: 22 (may contain duplicates)
- Total dependent repositories: 2,495 (may contain duplicates)
- Total versions: 106
- Total maintainers: 4
gem.coop: elasticsearch-rails
Ruby on Rails integrations for Elasticsearch.
- Homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html
- Documentation: http://www.rubydoc.info/gems/elasticsearch-rails/
- Licenses: Apache 2
- Latest release: 8.0.1 (published 4 months ago)
- Last Synced: 2026-01-08T16:31:32.645Z (1 day ago)
- Versions: 34
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 64,061,003 Total
- Docker Downloads: 434,203,038
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.188%
- Docker downloads count: 0.325%
- Downloads: 0.429%
- Maintainers (3)
rubygems.org: elasticsearch-rails
Ruby on Rails integrations for Elasticsearch.
- Homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html
- Documentation: http://www.rubydoc.info/gems/elasticsearch-rails/
- Licenses: Apache 2
- Latest release: 8.0.1 (published 4 months ago)
- Last Synced: 2026-01-08T14:06:53.812Z (1 day ago)
- Versions: 34
- Dependent Packages: 22
- Dependent Repositories: 2,495
- Downloads: 64,059,002 Total
- Docker Downloads: 434,203,038
-
Rankings:
- Docker downloads count: 0.39%
- Downloads: 0.438%
- Dependent repos count: 0.636%
- Stargazers count: 0.648%
- Average: 0.663%
- Forks count: 0.814%
- Dependent packages count: 1.051%
- Maintainers (3)
proxy.golang.org: github.com/elastic/elasticsearch-rails
- Homepage:
- Documentation: https://pkg.go.dev/github.com/elastic/elasticsearch-rails#section-documentation
- Licenses: apache-2.0
- Latest release: v8.0.1+incompatible (published 4 months ago)
- Last Synced: 2026-01-04T20:04:58.238Z (5 days ago)
- Versions: 28
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.508%
- Average: 6.726%
- Dependent repos count: 6.945%
gem.coop: elasticsearch-rails-origin
Ruby on Rails integrations for Elasticsearch.
- Homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html
- Documentation: http://www.rubydoc.info/gems/elasticsearch-rails-origin/
- Licenses: MIT
- Latest release: 7.2.6 (published almost 3 years ago)
- Last Synced: 2026-01-04T20:04:57.445Z (5 days ago)
- Versions: 5
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 4,526 Total
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 24.466%
- Downloads: 73.398%
- Maintainers (1)
rubygems.org: elasticsearch-rails-origin
Ruby on Rails integrations for Elasticsearch.
- Homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html
- Documentation: http://www.rubydoc.info/gems/elasticsearch-rails-origin/
- Licenses: MIT
- Latest release: 7.2.6 (published almost 3 years ago)
- Last Synced: 2026-01-04T20:04:57.438Z (5 days ago)
- Versions: 5
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 4,526 Total
-
Rankings:
- Stargazers count: 0.577%
- Forks count: 0.728%
- Dependent packages count: 15.706%
- Average: 30.737%
- Dependent repos count: 46.782%
- Downloads: 89.892%
- Maintainers (1)
Dependencies
- actions/checkout v2 composite
- elastic/elastic-github-actions/elasticsearch master composite
- ruby/setup-ruby v1 composite
- actions/checkout v2 composite
- elastic/elastic-github-actions/elasticsearch master composite
- ruby/setup-ruby v1 composite
- actions/checkout v2 composite
- elastic/elastic-github-actions/elasticsearch master composite
- ruby/setup-ruby v1 composite
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
- rspec >= 0 development
- yard >= 0 development
- ansi >= 0
- cane >= 0
- elasticsearch ~> 7
- pry >= 0
- rake ~> 12
- pry-nav >= 0 development
- rspec >= 0 development
- activemodel > 3 development
- bundler >= 0 development
- cane >= 0 development
- kaminari >= 0 development
- minitest >= 0 development
- mocha >= 0 development
- oj >= 0 development
- pry >= 0 development
- rake ~> 12 development
- require-prof >= 0 development
- ruby-prof >= 0 development
- shoulda-context >= 0 development
- simplecov >= 0 development
- sqlite3 >= 0 development
- test-unit >= 0 development
- turn >= 0 development
- will_paginate >= 0 development
- yard >= 0 development
- activesupport > 3
- elasticsearch ~> 7
- hashie >= 0
- pry-nav >= 0 development
- rspec >= 0 development
- bundler >= 0 development
- cane >= 0 development
- minitest >= 0 development
- mocha >= 0 development
- pry >= 0 development
- rails > 4 development
- rake ~> 12 development
- shoulda-context >= 0 development
- simplecov >= 0 development
- test-unit >= 0 development
- turn >= 0 development
- yard >= 0 development
- activemodel > 4
- activesupport > 4
- elasticsearch ~> 7
- elasticsearch-model = 7.2.1
- hashie >= 0
- elasticsearch-extensions >= 0 development
- mocha >= 0 development
- rack-test >= 0 development
- shoulda-context >= 0 development
- sinatra-contrib >= 0 development
- turn >= 0 development
- ansi >= 0
- elasticsearch >= 0
- elasticsearch-model >= 0
- elasticsearch-persistence >= 0
- hashie >= 0
- multi_json >= 0
- oj >= 0
- patron >= 0
- rake >= 0
- sinatra >= 0
- thin >= 0
- pry-nav >= 0 development
- rspec >= 0 development
- bundler >= 0 development
- cane >= 0 development
- lograge >= 0 development
- minitest >= 0 development
- mocha >= 0 development
- oj >= 0 development
- pry >= 0 development
- rails > 3.1 development
- rake ~> 12 development
- require-prof >= 0 development
- ruby-prof >= 0 development
- shoulda-context >= 0 development
- simplecov >= 0 development
- test-unit >= 0 development
- turn >= 0 development
- yard >= 0 development
Score: 33.497251049909075