appbase-swift: A Lightweight Swift Client for Elasticsearch

DZone 's Guide to

appbase-swift: A Lightweight Swift Client for Elasticsearch

A dev and industry exec explains why his team created this Swift client and how to get started harnessing the power of Elasticsearch on iOS and MacOS.

· Big Data Zone ·
Free Resource
Swift and Elasticsearch

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 We Built 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:

  1. Provide a lightweight library for querying right from iOS apps as well as Mac apps.
  2. 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> ?? [:]

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.

Swift and Elasticsearch

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.
Data visualization
big data ,elasticsearch ,swift ,swift tutorial

Published at DZone with permission of Siddharth Kothari , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}