What is in a record
Learn everything you need to know about Algolia records, including attributes, types, limits, formatting, nesting, and more.
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 |
objects | "lead_role": { "name": "Walter White", "portrayed_by": "Bryan Cranston" } |
arrays | "episodes": ["Crazy Handful of Nothin'", "Gray Matter"] |
Here’s an example of a typical record:
Integers and booleans are treated as strings by searchable attributes but treated as numerical values by numerical facets. For example, if you want to sort the results by the number of likes, Algolia will treat the like_count
attribute as a number, not a string.
Unique record identifier
The objectID
attribute is a unique identifier for each record.
You should set objectID
s yourself, based on your data. Since you use objectID
s to update and delete specific records, it’s easier if you’ve defined them yourself. If you don’t set objectID
s, Algolia generates them for you: you can check their values by browsing the index.
When you retrieve objects, objectID
s are in string format, even if you set them as integers. If you want to use integers in your app, convert objectID
into integers after retrieving the objects but make sure that all your objectID
s 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
objectID
inattributesToHighlight
orattributesToSnippet
, the engine ignores it. - You can’t exclude it from results. If you declare
objectID
inunretrievableAttributes
or omit it fromattributesToRetrieve
, the engine still returns it. For this reason,objectID
s mustn’t contain any sensitive data. - You can use it as a facet filter, but you can’t facet it. If you declare
objectID
inattributesForFaceting
, the engine ignores it. Faceting on a unique identifier makes little sense since every facet count would equal one.
Acceptable characters for objectID
s
objectID
strings can:
- Contain any character
- Be of any length as long as it fits the size limit for your plan.
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 function, the output may need further manipulation to produce an integer value in 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
_rankingInfo
snippetResult
_tags
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.
Reserved words aren’t searchable by default.
If you want to search _tags
or _geoloc
, you must add them to your 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.
Was this page helpful?