Home

Awesome

ElastiQ

Generate ElasticSearch query in Swift

GitHub release Language Carthage Compatible CocoaPods CocoaPodsDL

Feature

How to use

@objcMember
class Recipe: NSObject {
    dynamic var cookTimeMin: Int = 0
    dynamic var title: String = ""
}

let query = ElastiQ()
    .range(\Recipe.cookTimeMin, [.lt(30), .gte(10)])

let json = try! query.json()
print(String(data: json, encoding: .utf8))
//-------------------
{
  "query": {
    "range": {
      "cookTimeMin": {
        "gte":10,
        "lt":30
      }
    }
  }
}


let query = ElastiQ()
    .bool({ query in
        query.filter { filter in
            filter
                .term(\Recipe.title, "tomato")
                .range(\Recipe.cookTimeMin, .lt(30))
        }
    })

let json = try! query.json()
print(String(data: json, encoding: .utf8))
//----------------
{
  "query" : {
    "bool" : {
      "filter" : [
        {
          "term" : {
            "title" : "bean"
          }
        },
        {
          "range" : {
            "cookTimeMin" : {
              "lt" : 30
            }
          }
        }
      ]
    }
  }
}

TODO

Requirements

Installation

Carthage

github "sgr-ksmt/ElastiQ" ~> 0.7.1

CocoaPods

ElastiQ is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ElastiQ', '~> 0.7.1'

and run pod install

Manually Install

Download all *.swift files and put your project.

Change log

Change log is here.

Communication

License

ElastiQ is under MIT license. See the LICENSE file for more info.