Update a Field in all Objects

Hi,

I have a attribute that is in all of my objects. This field is a string that is concatenated from two strings.

The latter string is unique to the object.
The first string is the same for all objects and set by my application to be concatenated before I index my objects in Algolia.

Example:

`${globalPrefix}${object.some_string_property}`

The global prefix can change for all objects.

I would like to know if Ican perform any of the following solutions, and which you would recommend:

  1. Is there a way to partial_update_objects for all objects?
  2. Is there any way to have a field be a computed_filed?
  3. Is there a way for one of my query rules to always append the prefix to a result object?

Thanks,
Simon

Hi @simon.reilly,

Thanks for contacting Algolia and the clear example.

  1. Is there a way to partial_update_objects for all objects?

This sounds like the equivalent of a complete reindexing. Indeed, you could run partial_update_objects for all objects, but it would not happen “auto-magically” through Algolia. You would create a script (rake task if Ruby/Rails is your approach) and loop through all your database records updating them as needed based on the objectID.

  1. Is there any way to have a field be a computed_filed?

My guess is this is computed_field - let me know if that’s not the case. No, Algolia does not have a feature where it would run calculations using indexed attributes/values for you. As a schemaless index it holds the data you provide. The computed field would have to be pre-computed, like any other attribute/value pair, and indexed to Algolia.

  1. Is there a way for one of my query rules to always append the prefix to a result object?

No, a query rule would not be able to achieve this. Indeed, if this outcome (“append the prefix to a result object”) is consistent you can either handle it on the frontend by always adding it with JS to each hit, or a recommendation is for it to always be existing in the record already.

My current thought based on the description of ${globalPrefix}${object.some_string_property} is to not try to “merge” this into a single attribute in Algolia. Create two separate attributes:

{
    "name": "my object",
    "globalPrefix": "thePrefix",
    "someStringProperty": "theSuffix"
} 

This way you can handle it as you wish on the frontend (displaying tangible values in each object), and for any global partial_update_objects you can easily target the globalPrefix attribute.

Thanks for the detailed response - I will probably try a few of these and see what happens.

Simon

1 Like