Convert Figma logo to code with AI

elastic logoelasticsearch-ruby

Ruby integrations for Elasticsearch

1,967
597
1,967
9

Top Related Projects

Free and Open Source, Distributed, RESTful Search Engine

Intelligent search made easy

Quick Overview

The elasticsearch-ruby repository is the official Ruby client for Elasticsearch. It provides a set of libraries for interacting with Elasticsearch, including a low-level client, a high-level API client, and additional tools for working with Elasticsearch in Ruby applications.

Pros

  • Official client with direct support from Elastic
  • Comprehensive set of features covering both low-level and high-level operations
  • Well-documented and actively maintained
  • Supports multiple Elasticsearch versions

Cons

  • Learning curve for complex operations
  • Performance can be slower compared to direct HTTP requests for simple operations
  • Large dependency footprint
  • Some advanced features may require additional configuration

Code Examples

  1. Basic search query:
require 'elasticsearch'

client = Elasticsearch::Client.new

response = client.search(index: 'my_index', body: {
  query: {
    match: {
      title: 'ruby elasticsearch'
    }
  }
})

puts response['hits']['hits']
  1. Indexing a document:
client.index(
  index: 'my_index',
  id: 1,
  body: {
    title: 'Test Document',
    content: 'This is a test document for Elasticsearch'
  }
)
  1. Bulk indexing:
client.bulk(
  body: [
    { index: { _index: 'my_index', _id: 2 } },
    { title: 'Document 2', content: 'Content for document 2' },
    { index: { _index: 'my_index', _id: 3 } },
    { title: 'Document 3', content: 'Content for document 3' }
  ]
)

Getting Started

  1. Install the gem:

    gem install elasticsearch
    
  2. Create a client:

    require 'elasticsearch'
    
    client = Elasticsearch::Client.new(
      hosts: ['http://localhost:9200'],
      log: true
    )
    
  3. Perform operations:

    # Index a document
    client.index(index: 'test_index', id: 1, body: { title: 'Test' })
    
    # Search
    results = client.search(index: 'test_index', body: { query: { match: { title: 'Test' } } })
    

Competitor Comparisons

Free and Open Source, Distributed, RESTful Search Engine

Pros of Elasticsearch

  • Written in Java, offering high performance and scalability
  • More comprehensive feature set and direct access to core Elasticsearch functionality
  • Larger community and more extensive documentation

Cons of Elasticsearch

  • Steeper learning curve for developers not familiar with Java
  • Requires more system resources to run and maintain
  • More complex setup and configuration process

Code Comparison

Elasticsearch (Java):

SearchResponse response = client.prepareSearch("index")
    .setQuery(QueryBuilders.matchQuery("field", "value"))
    .setSize(10)
    .execute()
    .actionGet();

Elasticsearch-Ruby:

response = client.search(
  index: 'index',
  body: { query: { match: { field: 'value' } } },
  size: 10
)

Summary

Elasticsearch is the core Java-based project, offering full functionality and high performance, but with a steeper learning curve. Elasticsearch-Ruby is a Ruby client for Elasticsearch, providing a more Ruby-friendly interface but potentially lacking some advanced features. The choice between them depends on your programming language preference, performance requirements, and the level of direct control you need over Elasticsearch operations.

Intelligent search made easy

Pros of Searchkick

  • Simpler, more Ruby-like syntax for common Elasticsearch operations
  • Built-in support for faceted search, highlighting, and autocomplete
  • Automatic integration with ActiveRecord and other ORMs

Cons of Searchkick

  • Less flexible for complex Elasticsearch queries and configurations
  • May have performance overhead for large-scale applications
  • Limited to Ruby, while elasticsearch-ruby can be used with other JVM languages

Code Comparison

Searchkick:

Product.search("apples", where: {in_stock: true}, limit: 10)

elasticsearch-ruby:

client.search(index: 'products',
              body: {
                query: { match: { name: 'apples' } },
                filter: { term: { in_stock: true } },
                size: 10
              })

Summary

Searchkick offers a more user-friendly interface for Ruby developers, especially those working with Rails applications. It provides convenient features out of the box, making it easier to implement search functionality quickly. However, elasticsearch-ruby offers more flexibility and direct control over Elasticsearch operations, which may be preferable for complex use cases or when working with multiple programming languages. The choice between the two depends on the specific requirements of the project and the developer's familiarity with Elasticsearch.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Elasticsearch

7.17 8.14 8.15 main Build status

Download the latest version of Elasticsearch or sign-up for a free trial of Elastic Cloud.

This repository contains the official Elasticsearch Ruby client. The elasticsearch gem is a complete Elasticsearch client which uses two separate libraries:

Documentation

Please refer to the full documentation on elastic.co for comprehensive information.

Both elastic-transport and elasticsearch-api are documented. You can check the elastic-transport and the elasticsearch-api documentation at RubyDocs.

Installation

gem install elasticsearch

Refer to the Installation section of the getting started documentation.

Connecting

Refer to the Connecting section of the getting started documentation.

Usage

require 'elasticsearch'
client = Elasticsearch::Client.new(host: 'https://my-elasticsearch-host.example')
client.ping
client.search(q: 'test')

Refer to the official documentation for examples of how to use the most frequently called APIs and doc/examples for some practical examples.

For optimal performance, you should use a HTTP library which supports persistent ("keep-alive") connections, e.g. Patron or Typhoeus. These libraries are not dependencies of the Elasticsearch gems. Ensure you define a dependency for a HTTP library in your own application.

Check out these other official Ruby libraries for working with Elasticsearch:

Please see their respective READMEs for information and documentation.

Compatibility

We follow Ruby’s own maintenance policy and officially support all currently maintained versions per Ruby Maintenance Branches.

Language clients are forward compatible; meaning that clients support communicating with greater or equal minor versions of Elasticsearch without breaking. It does not mean that the client automatically supports new features of newer Elasticsearch versions; it is only possible after a release of a new client version. For example, a 8.12 client version won't automatically support the new features of the 8.13 version of Elasticsearch, the 8.13 client version is required for that. Elasticsearch language clients are only backwards compatible with default distributions and without guarantees made.

Gem VersionElasticsearch VersionSupported
7.x→7.x7.17
8.x→8.x8.x
main→main

Development

See CONTRIBUTING.

License

This software is licensed under the Apache 2 license. See NOTICE.