How can i get the ObjectID from the hits i get back from algolia

I am trying to get ObjectID of a hit document.
I have tried to extract it from query result data but i always get null,
i have no problem getting other fields.

Hi @amangupta0546 - fellow Algolia user here. ObjectIDs are retrieved by default, so as a starting point I’d recommend ensuring you’re not specifically excluding ObjectID as a retrievable attribute in your settings.

In the Algolia dashboard, if ObjectID is appearing under the results provided in the Browse tab, you should be good to go. I would confirm by reviewing your settings in the Retrieved Attributes section:

Indices => Configuration tab => Retrieved attributes

If all looks well there, I’d next refocus on the client. Ensure your settings for attributesToRetrieve , unretrievableAttributes, and responseFields do not specifically exclude ObjectID.

If none of those provide any clues, let us know what client you’re working with and I’m sure an Algolian will respond in short order.

Good luck!

Thanks chad for the answer,
I just found out my problem was using different syntax for getting the ObjectID

I was using String objectID =['objectID]

but the syntax to return objectID was found to be,

String objectID = hitItem.objectID;

ill without doubt keep your advice in mind too for future.

1 Like