Generate ElasticSearch query in Swift
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ElastiQ.xcodeproj
ElastiQ.xcworkspace
ElastiQ
ElastiQTests
ExamplePlayground.playground
Sources
.gitignore
.swift-version
ElastiQ.podspec
LICENSE
README.md

README.md

ElastiQ

Generate ElasticSearch query in Swift

GitHub release Language Carthage Compatible CocoaPods CocoaPodsDL

Feature

  • MethodChain
  • Type-Safe.
  • KeyPath compatible.

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

  • from/size/source/field
  • match
  • aggregation
  • function score query

Requirements

  • iOS 9.0+
  • Xcode 9+
  • Swift 4+

Installation

Carthage

  • Add the following to your Cartfile:
github "sgr-ksmt/ElastiQ" ~> 0.7.1
  • Run carthage update
  • Add the framework as described.
    Details: Carthage Readme

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

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.💪

License

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