Search API Client for Kotlin
A computer on a search page, with recommendations being inserted on the side

What is Algolia

Algolia empowers modern developers to build world class search and discovery experiences without any DevOps. 

Libraries with every major language and framework make it easy to enrich your users' experiences. 

Features

  • Gives API access to all Algolia functionality, settings, advanced features, and ML/AI products
  • With or without Android Studio, or Intellij Idea
  • Frontend Android projects using Kotlin
  • Backend JVM projects using Kotlin
  • Kotlin multiplatform, Kotlinx serialization, Ktor HTTP client
  • Domain Specific Locator (DSL) 
  • Background retry strategy to ensure uptime
  • Seamless batching via iterators to optimize number of network calls
  • Zero downtime reindexing feature

Version

  • Compatible with Kotlin 1.3.30 and higher

Related Integrations

  • InstantSearch for Android
  • Autocomplete

Key links


Get started

INSTALL

1// Gradle
2repositories {
3    mavenCentral()
4}
5
6dependencies {
7    implementation "com.algolia:algoliasearch-client-kotlin:$kotlin_client_version"
8    // for Gradle version < 6.0, use the following instead
9    implementation "com.algolia:algoliasearch-client-kotlin-jvm:$kotlin_client_version"
10    // Choose one of the following HTTP clients
11    implementation "io.ktor:ktor-client-apache:$ktor_version"
12    implementation "io.ktor:ktor-client-okhttp:$ktor_version"
13    implementation "io.ktor:ktor-client-android:$ktor_version"
14    implementation "io.ktor:ktor-client-cio:$ktor_version"
15    implementation "io.ktor:ktor-client-jetty:$ktor_version"
16}

INDEX

1// With JsonObject
2val json = listOf(
3    ObjectID("myID1") to json {
4        "firstname" to "Jimmie"
5        "lastname" to "Barninger"
6    },
7    ObjectID("myID1") to json {
8        "firstname" to "Warren"
9        "lastname" to "Speach"
10    }
11)
12
13index.replaceObjects(json)
14
15// With serializable class
16@Serializable
17data class Contact(
18    val firstname: String,
19    val lastname: String,
20    override val objectID: ObjectID
21) : Indexable
22
23val contacts = listOf(
24    Contact("Jimmie", "Barninger", ObjectID("myID")),
25    Contact("Jimmie", "Barninger", ObjectID("myID"))
26)
27
28index.replaceObjects(Contact.serializer(), contacts)

SEARCH

1@Serializable
2data class Contact(
3    val firstname: String,
4    val lastname: String
5)
6
7val indexName = IndexName("contacts")
8val index = client.initIndex(indexName)
9val query = queryBuilder {
10    query = "query string"
11    hitsPerPage = 50
12    attributesToRetrieve {
13        +"firstname"
14        +"lastname"
15    }
16}
17val result = index.search(query)
18
19result.hits.deserialize(Contact.serializer())
Get started for freeExplore all developer docs

Built with Algolia

Frontend Tools
Templates & Starters

Ecommerce Starter

Starter for product search powered by Algolia InstantSearch

  • vuejs
  • react
  • angular
  • javascript