TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by sgr-ksmt.
Generate ElasticSearch query in Swift
@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
}
}
}
]
}
}
}
Download all *.swift
files and put your project.
Change log is here.
ElastiQ is under MIT license. See the LICENSE file for more info.