Algolia records
Algolia uses JSON to model records.
Your records can have attributes with the following formats:
| Format | Example |
|---|---|
| string | "title": "Breaking Bad" |
| integer | "like_count": 978 |
| float | "avg_rating": 1.23456 |
| boolean | "featured": true |
| object | "lead_role": { "name": "Walter White", "portrayed_by": "Bryan Cranston" } |
| array | "episodes": ["Crazy Handful of Nothin'", "Gray Matter"] |
For example,
this record includes different data types and the _tags reserved attribute:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[
{
"objectID": 42,
"title": "Breaking Bad",
"episodes": [
"Crazy Handful of Nothin'",
"Gray Matter"
],
"like_count": 978,
"avg_rating": 1.23456,
"air_date": 1356846157,
"featured": true,
"lead_role": {
"name": "Walter White",
"portrayed_by": "Bryan Cranston"
},
"_tags": ["tv series", "drugs"]
}
]
Although integers and booleans are treated as strings for searchable attributes
they’re interpreted as numbers for numerical facets.
For example, Algolia treats like_count as a number.
Unique record identifier
The objectID attribute is a unique identifier for each record.
You should set objectIDs yourself, based on your data.
Since you use objectIDs to update and delete specific records,
it’s easier if you’ve defined them yourself.
If you don’t set objectIDs, Algolia assigns them automatically:
you can check their values by browsing the index.
When you retrieve objects, objectIDs are in string format, even if you set them as integers.
If you want to use integers in your app, convert objectID to integers after retrieving the objects but make sure that all your objectIDs contain integer values.
Since objectID uniquely identifies your objects:
- You can search for it by declaring it as a
searchableAttributes. - You can’t highlight or snippet it. If you declare
objectIDinattributesToHighlightorattributesToSnippet, Algolia ignores it. - You can’t exclude it from results. If you declare
objectIDinunretrievableAttributesor omit it fromattributesToRetrieve, Algolia still returns it. For this reason,objectIDs mustn’t contain any sensitive data. - You can use it as a facet filter, but you can’t facet it. If you declare
objectIDinattributesForFaceting, Algolia ignores it. Faceting on a unique identifier makes little sense since every facet count would equal one.
Acceptable characters for objectIDs
objectID strings can:
- Contain any character
- Be of any length as the record fits within your plan’s size limit.
Dates
Date attributes must be formatted as Unix timestamps (for example, 1435735848).
To convert ISO 8601 formatted dates to Unix timestamps, use the appropriate function for your chosen programming language:
- Android -
Date() - Go -
time.Unix - Java/Scala (java.time package) -
getTime() - JavaScript -
getTime() - Kotlin -
kotlinx-datetime - .Net -
ToUnixTimeSeconds - PHP -
strtotime - Python -
datetime - Ruby -
date.to_time - Swift -
NSDate(withTimeIntervalSince1970:)
Depending on the language, the output might require conversion from milliseconds to seconds.
Reserved attribute names
Some attribute names are reserved by Algolia. You may be able to use them but be aware of their restrictions.
distinctSeqId_geoloc_highlightResult_rankingInfosnippetResult_tags
The _collections attribute is reserved only if you’re using InstantSearch to implement a collections page.
If you’re not using InstantSearch, _collections behaves like any other attribute.
In your records
In a record, you can use the _tags or _geoloc attribute names but they have an imposed schema.
Other attribute names are schema-agnostic.
Algolia doesn’t search reserved attribute names unless you explicitly include them in searchableAttributes.
In the search response
Algolia returns _highlightResult, _snippetResult, _rankingInfo, and _distinctSeqID in the search response.
They’re reserved Algolia attributes tied to specific features.
To avoid conflicts, don’t specify these attribute names in your records.