Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-query-builder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-query-builder

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EsQueryBuilder

Build Status Code Climate Coverage Status Dependency Status

A query builder for Elasticsearch in Ruby.

Usage

gem 'es-query-builder'
builder = EsQueryBuilder.new(
  # Fields allowed searching with match query.
  query_fields: ['field1'],
  # Fields for filtering. Queries for these fields do not affect search score.
  filter_fields: ['field2']
)

query = builder.build(query_string_given_by_user)

body = 
  if query.nil?
    # Empty query
    { size: 0 }
  else
    # Add other conditions, such as sort, highlight, fields and so on.
    {
      query: query,
      sort: { ... }
    }
  end

client = Elasticsearch::Client.new(host: 'http://server:9200')
client.search({
  index: 'index_name',
  type: 'type_name',
  body: body
})
# => #<Hash>

Description

EsQueryBuilder converts a query string into a corresponding hash object for elasticsearch-ruby.

Elasticsearch supports query_string query dsl which is very useful to use internally, but too powerful to use as public interface. Allowing anonymous users to use the dsl may cause not only performance problems but also security risks if your index includes secret types.

This gem accepts the query_string-query-dsl-like string and converts the string into a query object using other query dsls. At the same time it sanitizes fields in the query.

FAQs

Package last updated on 24 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc