Concepts / Sending and managing data / What is in a record
Sep. 26, 2019

What Is in a Record

An Example of a Typical Record

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[
  {
    "objectID": 42,               // record identifier
    "title": "Breaking Bad",      // string attribute
    "episodes": [                 // array of strings attribute
      "Crazy Handful of Nothin'",
      "Gray Matter"
    ],
    "like_count": 978,            // integer attribute
    "avg_rating": 1.23456,        // float attribute
    "air_date": 1356846157,       // date as timestamp
    "featured": true,             // boolean attribute
    "actors": [                   // nested objects attribute
      {
        "name": "Walter White",
        "portrayed_by": "Bryan Cranston"
      },
      {
        "name": "Skyler White",
        "portrayed_by": "Anna Gunn"
      }
    ],
    "_tags": "tv series, drugs"
  }
]

Accepted Datatypes for your Attributes

Records in Algolia are modeled with JSON, which makes them easier to configure and more flexible.

You can index data attributes that have the following format:

  • string: "foo"
  • integer/float: 12 or 12.34
  • boolean: true
  • nested objects: { "sub": { "a1": "v1", "a2": "v2" } }
  • array (of strings, integers, floats, booleans, nested objects, arrays): ["foo", "bar"]

Unique identifier - ObjectID

The engine requires every object to be identified by a unique objectID. We recommend you set your own internal IDs. When you don’t, Algolia generates them for you (like “228506501”), and you can retrieve them by browsing the index. Later, you’ll need to use the objectIDs for updates and deletes.

Please note that when you retrieve objects, objectIDs are always returned as string values, even if you’ve provided a custom objectID as an integer. If you wish to use only integers in your application, and if you are confident that you only have integer values as objectIDs, you can safely cast every objectID as an integer after retrieving the objects.

Because the objectID is used as a unique identifier for your objects, it gets special treatment by Algolia:

  • It can be searched by declaring it as a searchableAttributes.
  • It can’t be highlighted nor snippeted. If objectID is declared in attributesToHighlight or attributesToSnippet, it will be ignored.
  • It cannot be excluded from the results. If objectID is declared in unretrievableAttributes or omitted from attributesToRetrieve, it will still be returned.
  • It can be used as a facet filter, but it can’t be faceted. If objectID is declared in attributesForFaceting, it will be ignored. Faceting on a unique identifier makes little sense anyway, since every facet count would be equal to one.

Dates

Date attributes should be formatted as Unix timestamps (e.g., 1435735848) if you want to filter or sort by date. The Algolia engine doesn’t interpret dates as ISO 8601 strings, so you must convert your dates into numeric values.

Reserved Attribute Names

The Algolia API uses underscore prefixes to identify reserved attributes name.

Records

In a record, you can use attribute names like _tags or _geoloc but they have an imposed schema. All other attribute names are schema-agnostic.

Note: Reserved words are not searchable by default. If you wish to search into _tags and/or _geoloc, you need to add these to your searchableAttributes. However, keep in mind that once you use searchableAttributes for any attribute, you need to list all attributes you wish to search into.

Search Response

In the search response, Algolia will return attribute names like: _highlightResult, _snippetResult, _rankingInfo or _distinctSeqID. These are reserved Algolia words that are tied to specific features. If you use them in your records, it will create conflicts.

Did you find this page helpful?