0.07
There's a lot of open issues
Ruby integrations for OpenSearch (client, API, etc.)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

Runtime

 Project Readme

Integration Chat PRs welcome!

OpenSearch logo

OpenSearch Ruby Client

  • Welcome!
  • Project Resources
  • Code of Conduct
  • License
  • Copyright

Welcome!

opensearch-ruby is a community-driven, open source fork of elasticsearch-ruby licensed under the Apache v2.0 License. For more information, see opensearch.org.

Setup

To add the client to your project, install it using RubyGem

gem install opensearch-ruby

or, install it from a source code checkout:

git clone https://github.com/opensearch-project/opensearch-ruby.git
cd opensearch-ruby/opensearch
gem build opensearch.gemspec
gem install opensearch-ruby-<version>.gem

Import the client as a module:

require 'opensearch'

If you prefer to add the client manually or just want to examine the source code, see opensearch-ruby on GitHub.

Sample code

require 'opensearch'


# If you want to use authentication credentials
client = OpenSearch::Client.new(
  host: 'https://admin:admin@localhost:9200',    # For testing only. Don't store credentials in code.
  transport_options: { ssl: { verify: false } }  # For testing only. Use certificate for validation.
)

# If you don't want to use authentication credentials
#client = OpenSearch::Client.new url: 'http://localhost:9200', log: true

# Create an index with non-default settings.
index_name = 'ruby-test-index'
index_body = {
  'settings': {
    'index': {
      'number_of_shards': 4
    }
  }
}

response = client.indices.create(
  index: index_name,
  body: index_body
)

puts 'Creating index:'
puts response


# Add a document to the index.
document = {
  'title': 'Moneyball',
  'director': 'Bennett Miller',
  'year': '2011'
}
id = '1'

response = client.index(
  index: index_name,
  body: document,
  id: id,
  refresh: true
)

puts 'Adding document:'
puts response



# Search for the document.
q = 'miller'
query = {
  'size': 5,
  'query': {
    'multi_match': {
      'query': q,
      'fields': ['title^2', 'director']
    }
  }
}

response = client.search(
  body: query,
  index: index_name
)
puts 'Search results:'
puts response


# Delete the document.
response = client.delete(
  index: index_name,
  id: id
)

puts 'Deleting document:'
puts response

# Delete the index.
response = client.indices.delete(
  index: index_name
)

puts 'Deleting index:'
puts response
    

AWS Managed Opensearch with Sigv4

If you have the need to sign every request with AWS Sigv4 to be able to communicate with an Opensearch cluster managed by AWS, use opensearch-aws-sigv4 gem in place of opensearch-ruby gem.

For more information, checkout the README of opensearch-aws-sigv4

Project Resources

Code of Conduct

This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact opensource-codeofconduct@amazon.com with any additional questions or comments.

License

This project is licensed under the Apache v2.0 License.

Copyright

Copyright OpenSearch Contributors. See NOTICE for details.