Status: Experimental / In Progress
A simple DSL to make it easier to construct Elasticsearch queries in Swift.
- Builder Syntax supporting conditionals and loops
- Simple typing system for scalar values
- Doesn't try to define the whole syntax language, just enough to provide structure.
Static
@ElasticsearchQueryBuilder
func build() -> some esb.QueryDSL {
esb.Query {
esb.Bool {
esb.Key("match_bool_prefix") {
[
"message": "quick brown f"
]
}
}
}
esb.Pagination.init(size: 20)
}
Conditionals
@ElasticsearchQueryBuilder
func build(message: String?) -> some esb.QueryDSL {
esb.Query {
esb.Bool {
if let message {
esb.Key("match") {
[
"message": .string(message)
]
}
}
}
}
}
Loops
@ElasticsearchQueryBuilder
func build(messages: [String]) -> some esb.QueryDSL {
esb.Query {
esb.Bool {
esb.Should {
for message in messages {
esb.Key("match") {
[
"message": .string(message)
]
}
}
}
}
}
}
This library is released under the MIT license. See LICENSE for details.