We’re excited to officially announce appbase-swift, a lightweight ElasticSearch/appbase.io client for Swift. Making it easier than ever to build a great search experience for iOS and Mac platforms.

Why Did We Build It

Similar to the companion library we announced recently for Android, we first set out to create appbase-swift as there were no well-maintained ElasticSearch clients out there for Swift. This remains true even today.

We have kept these design goals in mind:

Provide a lightweight library for querying right from iOS apps as well as Mac apps. Only focus on document and search APIs. We hope you aren’t planning to update your cluster settings from a mobile app 😉. Ideally, you are using a hosted environment like appbase.io which provides granular security controls.

Getting Started

It’s really easy to get started with it.

If you don’t already have an ElasticSearch index (called an app in appbase.io), you can create one for free from appbase.io dashboard.

Next, we will use the app and the API credentials to instantiate the client.

let client = Client.init(url: ELASTICSEARCH_URL, app: APPNAME, credentials: CREDENTIALS)

Once we have the client instantiated, we can then use the index, update, and search methods. For example, a search method call would look like this:

let body:[String:Any] = [

"query": [

"match": [

"title": "The Young Messiah"

]

]

]; client.search(type: "SwiftClientES", body: body,completionHandler: { (json, response, error) in

var json = json as! Dictionary<String, Any>

json = json["hits"] as? Dictionary<String, Any> ?? [:]

print(json)

})

The auto-generated docs are available over here. You can also checkout the quickstart for the client over here. Here’s an example app showing the usage of the client.

Image: Demo repository showing the above app https://github.com/harsh-2711/SwiftElasticSearchDemo

The client is licensed under Apache 2.0. We welcome 👋 contributions.

We’re working next on adding a declarative UI component for building a search bar for iOS Apps.

We’re also working on adding direct support for recording search analytics from the client, making it easier to understand how your end-users are using search and the business ROI from it.