elasticsearch-dsl.cr

A Crystal DSL for Elasticsearch

elasticsearch-dsl

A Crystal DSL for Elasticsearch. It is partially inspired by the Ruby Elasticsearch DSL.

WARNING:

THIS LIBRARY IS A WORK IN PROGRESS & API IS A MOVING TARGET.

Installation

Add this to your application's shard.yml:

dependencies:
  elasticsearch-dsl:
    github: newtonapple/elasticsearch-dsl

Usage

require "elasticsearch-dsl"

include Elasticsearch::DSL::Search
include Queries

bool_query = search {
  query {
    bool {
      must(MultiMatch) {
        fields ["title^2", "description", "body"]
        query "metaprogramming"
      }
      should(MatchPhrase) {
        match_phrase("body") {
          query "crystal magic"
        }
      }
    }
  }
}

puts bool_query.to_pretty_json
# =>
# {
#   "query": {
#     "bool": {
#       "must": {
#         "multi_match":{
#           "fields": ["title^2", "description", "body"],
#           "query": "metaprogramming"
#         }
#       },
#       "should": {
#         "match_phrase": {
#           "body": {
#             "query": "crystal magic"
#           }
#         }
#       }
#     }
#   }
# }

Please see spec for more examples.

Contributors

Repository

elasticsearch-dsl.cr

Owner
Statistic
  • 1
  • 0
  • 0
  • 0
  • 0
  • over 5 years ago
  • August 28, 2018
License

MIT License

Links
Synced at

Thu, 02 May 2024 07:52:33 GMT

Languages