algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
178 stars 45 forks source link

How to add new record attribute when using partialUpdates #59

Closed matrix4123 closed 4 years ago

matrix4123 commented 4 years ago

When partialUpdates is enabled, a new attribute was not detected and added to my records. Was curious if there was any way to detect a completely new attribute added to the record and add it.

Haroenv commented 4 years ago

I would put that attribute in the "modified" array as well, when you're just adding it. At a later point you can remove that entry again to prevent unneeded updates.

The ideal way to fill the modified array is to have the hash of the object itself (minus the hash itself of course). This way it will always update when something in the object updates.

matrix4123 commented 4 years ago

@Haroenv What array are you referring too? I don't see any documentation specifically for "modified".

vscncls commented 4 years ago

I'm having the same problem, doing the partial update manually (as shown in https://www.algolia.com/doc/api-reference/api-methods/partial-update-objects/) works just fine

Haroenv commented 4 years ago

Sorry, I meant to ask what your schema of your object is, as well as what you have written inside matchFields https://github.com/algolia/gatsby-plugin-algolia#advanced

vscncls commented 4 years ago

Solved my problem by adding a updatedAt field to my queries and then adding matchFields: ['updatedAt']

matrix4123 commented 4 years ago

I added an "UpdatedAt" previously... but in my case I am scraping the UpdatedAt from a remote object store, so this value doesn't change after I add a new field.

vscncls commented 4 years ago

you could add the name of the new field to the matchFields array, something like this should work

matchFields: ['updatedAt', 'mynewfield']

then, everytime the value of mynewfield or updatedAt is different than the one on your index, that entire record will be updated

Haroenv commented 4 years ago

I think what @vscncls is suggesting makes the most sense, so I'll close the issue for now, in case it's still not solved the issue, don't hesitate posting an example of the dataset + full Gatsby setup where we can reproduce