All Projects → elastic → Elasticsearch Rails

elastic / Elasticsearch Rails

Licence: apache-2.0
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to Elasticsearch Rails

Active record Events
Manage timestamps in ActiveRecord models
Stars: ✭ 109 (-96.24%)
Mutual labels:  activerecord, rails, ruby-on-rails
squint
Search PostgreSQL jsonb and hstore columns
Stars: ✭ 26 (-99.1%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-cockroachdb-adapter
CockroachDB adapter for ActiveRecord.
Stars: ✭ 90 (-96.89%)
Mutual labels:  activerecord, ruby-on-rails
u-observers
Simple and powerful implementation of the observer pattern.
Stars: ✭ 31 (-98.93%)
Mutual labels:  activerecord, activemodel
prefixed ids
Friendly Prefixed IDs for your Ruby on Rails models
Stars: ✭ 159 (-94.51%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-setops
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Stars: ✭ 21 (-99.27%)
Mutual labels:  activerecord, ruby-on-rails
Elastichd
Elasticsearch 可视化DashBoard, 支持Es监控、实时搜索,Index template快捷替换修改,索引列表信息查看, SQL converts to DSL等
Stars: ✭ 2,993 (+3.35%)
Mutual labels:  elastic, elasticsearch
Elastix
A simple Elasticsearch REST client written in Elixir.
Stars: ✭ 231 (-92.02%)
Mutual labels:  elastic, elasticsearch
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (-99.03%)
Mutual labels:  activerecord, ruby-on-rails
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (-97.93%)
Mutual labels:  activerecord, ruby-on-rails
Public activity
Easy activity tracking for models - similar to Github's Public Activity
Stars: ✭ 2,822 (-2.56%)
Mutual labels:  activerecord, rails
active record-updated at
Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
Stars: ✭ 27 (-99.07%)
Mutual labels:  activerecord, ruby-on-rails
duck record
Used for creating virtual models like ActiveType or ModelAttribute does.
Stars: ✭ 23 (-99.21%)
Mutual labels:  activerecord, activemodel
nxt state machine
A simple but powerful state machine implementation.
Stars: ✭ 14 (-99.52%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-crate-adapter
Ruby on Rails ActiveRecord adapter for CrateDB
Stars: ✭ 27 (-99.07%)
Mutual labels:  activerecord, ruby-on-rails
activeentity
Active Record without Database
Stars: ✭ 46 (-98.41%)
Mutual labels:  activerecord, activemodel
Clowne
A flexible gem for cloning models
Stars: ✭ 260 (-91.02%)
Mutual labels:  activerecord, rails
Docker Elastic Stack
ELK Stack Dockerfile
Stars: ✭ 175 (-93.96%)
Mutual labels:  elastic, elasticsearch
Elasticsearch Comrade
Elasticsearch admin panel built for ops and monitoring
Stars: ✭ 214 (-92.61%)
Mutual labels:  elastic, elasticsearch
rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (-99.27%)
Mutual labels:  activerecord, ruby-on-rails

Elasticsearch

Ruby 2.7 Ruby 2.6 Ruby 2.5 Ruby 2.4 JRuby Code Climate

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

To use an unreleased version, add it to your Gemfile for Bundler:

gem 'elasticsearch-model', github: 'elastic/elasticsearch-rails', branch: '5.x'
gem 'elasticsearch-rails', github: 'elastic/elasticsearch-rails', branch: '5.x'

Compatibility

The libraries are compatible with Ruby 2.4 and higher.

The version numbers follow the Elasticsearch major versions. The main branch is compatible with the latest Elasticsearch stack stable release.

Rubygem Elasticsearch
0.1 1.x
2.x 2.x
5.x 5.x
6.x 6.x
main 7.x

Use a release that matches the major version of Elasticsearch in your stack. Each client version is backwards compatible with all minor versions of the same major version.

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:

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-oss: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", "_type"=>"article", "_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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].