Code Monkey home page Code Monkey logo

arelastic's Introduction

Build Status Code Climate

Arelastic

Arelastic is a Elasticsearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries

It is intended to be a framework framework; that is, you can build your own ORM with it.

One example is Elastic Record

Usage

Search

search = Arelastic::Builders::Search['name']

# Name equals red
search.eq('red').as_elastic
# => {"term"=>{"name"=>"red"}}

# Negation
search.eq("red").negate.as_elastic
# => {"bool"=>{"must_not"=>{"term"=>{:name=>"red"}}}}

Limit & Offset

# Limit
Arelastic::Searches::Size.new(20).as_elastic
# => {"size"=>20}

# Offset
Arelastic::Searches::From.new(20).as_elastic
# => {"from"=>20}

Ordering

sort_field = Arelastic::Sorts::Field.new('price' => 'asc')
sort_field.as_elastic
#  => {'price' => 'asc'}

sort = Arelastic::Searches::Sort.new([sort_field])
sort.as_elastic
# => {"sort"=>[{"price"=>"asc"}]}

Putting It All Together

search = [
 Arelastic::Searches::Query.new(Arelastic::Builders::Search['name'].eq('Fun')),
 Arelastic::Searches::Size.new(20),
 Arelastic::Searches::From.new(20),
 Arelastic::Searches::Sort.new([Arelastic::Sorts::Field.new('price' => 'asc')])
]
Arelastic::Nodes::HashGroup.new(search).as_elastic
# => {"query"=>{"term"=>{"name"=>"Fun"}}, "size"=>20, "from"=>20, "sort"=>[{"price"=>"asc"}]}

Some helpful Arel builders can be found here.

arelastic's People

Contributors

austenmadden avatar bullfight avatar dcromer avatar ebarendt avatar malept avatar matthuhiggins avatar miloprice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.