There's a lot of open issues
No release in over a year
Create Elasticsearch models and mappings from code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 2.0
~> 0
~> 10.0
~> 3.0

Runtime

 Project Readme

Dry::ElasticModel Gem Version Build Status Test Coverage Maintainability

Installation

Add this line to your application's Gemfile:

gem 'dry-elastic_model'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dry-elastic_model

Usage

Release

  1. Bump VERSION and push a commit to master
  2. $ gem build dry-elastic_model.gemspec
  3. $ gem push dry-elastic_model-${VERSION}.gem

This gem was created to provide a thin layer between Elasticsearch models mapping and Ruby objects. Right now, if you want to build your own Elasticsearch wrapper, you're on your own when it comes to creating document mappings and mapping ES documents to Ruby code, which can be painful especially if you want to also validate them before pushing.

Responsibilities of this library:

  • models that represent Elasticsearch documents
  • converting and validating Ruby objects to Elasticsearch documents
  • converting & validating Elasticsearch documents to Ruby objects
  • providing mapping out-of-box based on created models

Sample model:

  class FooBar < Dry::ElasticModel::Base
    field :text_field, :text
    field :newly_added_text_field, :text, allow_missing: true
    field :keyword_field, :keyword, index: false
    field :date_field, :date
    field :long_field, :long
    field :double_field, :double
    field :boolean_field, :boolean
    field :ip_field, :ip
    list  :list_text_field, :text
    range :range_long_field, :long
  end

This corresponds to following Elasticsearch mapping (calling Foo.mapping.to_json):

{
  "foobar": {
    "properties": {
      "text_field": {
        "type": "text",
        "index": "not_analyzed"
      },
      "newly_added_text_field": {
        "type": "text",
        "index": "not_analyzed"
      },
      "keyword_field": {
        "type": "keyword",
        "index": false
      },
      "date_field": {
        "type": "date",
        "format": "strict_date_optional_time||epoch_millis"
      },
      "long_field": {
        "type": "long"
      },
      "double_field": {
        "type": "double"
      },
      "boolean_field": {
        "type": "boolean"
      },
      "ip_field": {
        "type": "ip"
      },
      "list_text_field": {
        "type": "text"
      },
      "range_long_field": {
        "type": "long_range"
      }
    }
  }
}

Development

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

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

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

License

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

Code of Conduct

Everyone interacting in the Dry::ElasticModel project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.