0.0
The project is in a healthy, maintained state
Provides a familiar ActiveRecord-like interface for working with Elasticsearch
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.20
~> 0.5.0
~> 3.9
~> 0.21.2
~> 2.18
~> 6.6.3

Runtime

 Project Readme

stretchy-model

Stretchy Image

Stretchy provides Elasticsearch/Opensearch models in Rails applications with an Rails-like model interface.

Features

Stretchy simplifies the process of querying, aggregating, and managing Elasticsearch-backed models, allowing Rails developers to work with search indices as comfortably as they would with traditional Rails models.

  • Models fully back by Elasticsearch/Opensearch
  • Chain queries, scopes and aggregations
  • Reduce Elasticsearch query complexity
  • Support for time-based indices and aliases
  • Associations to both ActiveRecord models and StretchyModel
  • Bulk Operations made easy
  • Ingest and Search Pipelines
  • Machine Learning
  • Vector and Neural search
  • Integrated RAG and LLM connectors
  • Validations, custom attributes, and more...

Follow the guides to learn more about:

Read the Documentation or follow the examples below:

Examples

Installation

Install the gem and add to the application's Gemfile by executing:

 bundle add stretchy-model

If bundler is not being used to manage dependencies, install the gem by executing:

  gem install stretchy-model

Tip

If using OpenSearch make sure to add the gem to your Gemfile.

bundle add opensearch-ruby

Rails Configuration
rails credentials:edit

Add elasticsearch credentials

elasticsearch:
   url: localhost:9200

# or if using opensearch
# opensearch:
#    host: https://localhost:9200
#    user: admin
#    password: admin
#    transport_options:
#       ssl:
#         verify: false

Create an initializer

config/initializers/stretchy.rb

Stretchy.configure do |config|
    config.client = Elasticsearch::Client.new Rails.application.credentials.elasticsearch
    # or if using OpenSearch
    # config.client = OpenSearch::Client.new Rails.application.credentials.opensearch
end

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

Testing

Act

Run github action workflow locally

brew install act --HEAD
act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:runner-latest
Elasticsearch
docker-compose up elasticsearch
bundle exec rspec
Opensearch
docker-compose up opensearch
ENV['BACKEND']=opensearch bundle rspec 

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/theablefew/stretchy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.