algolia / firestore-algolia-search

Apache License 2.0
112 stars 35 forks source link

Algolia index not updating fields changed to null value. #61

Closed asentris closed 3 years ago

asentris commented 3 years ago

When I update a field value within a Firestore document to null, the extension executes, but does not actually update the value in the Algolia index. I would assume the Algolia value would be deleted from the index, as null values are not transferred from Firestore to Algolia.

smomin commented 3 years ago

Currently this is not possible with the approach I have taken. I am thinking through an approach that will clean up null attributes. Will update when I have a solution.

smomin commented 3 years ago

How often are you setting attributes to null? Can you send me examples so I can see if there are alternative solutions I can think through?

asentris commented 3 years ago

The attributes aren't set to null very often. Example: a document may have an attribute that was mistakenly given a value (by a user), so it is later corrected to null.

Haroenv commented 3 years ago

https://discourse.algolia.com/t/deleting-attributes-in-partial-updates/10154 I think we might be better off updating the objects altogether instead of partially updating. It doesn't have a difference in cost and will solve this issue. Deleting objects alltogether isn't solved by just swapping partialUpdate to save though

Haroenv commented 3 years ago

this issue is a duplicate of #60

smomin commented 3 years ago

@Haroenv The partialUpdate was used to manage race conditions that could occur from the cold start up of the Cloud functions. Before this approach, I had an extra call to the Firestore db to sync up the records after then Cloud Function was warmed up, but this would be a Firestore cost.

I am currently considering looping through the payload for null values. If I encounter any fields with null values, i will use the saveObject method. However, I will have to make a call to Firestore db to refresh the data just in case if the data has changed.

saifurrehmanx commented 3 years ago

@Haroenv The partialUpdate was used to manage race conditions that could occur from the cold start up of the Cloud functions. Before this approach, I had an extra call to the Firestore db to sync up the records after then Cloud Function was warmed up, but this would be a Firestore cost.

I am currently considering looping through the payload for null values. If I encounter any fields with null values, i will use the saveObject method. However, I will have to make a call to Firestore db to refresh the data just in case if the data has changed.

Ok but what if someone uses firebase.firestore.FieldValue.delete() to remove the field?