Is there alternative to batch update in algolia

enterprise_id: "12345"
enterprise_name:"Meta Securities"
invoice:111
quotation:41
customers:83
contact:987654321
geoloc:{ lat: "26.78552698", lng: "85.03094429" }

can i use above single record to rank record related to below by enterprise_id based on low price and nearest place so that i dont need to batch update multiple(it can be two or more than two) records for increment in invoice count or quotation count like in above record. if yes how can i do so?

enterprise_id:"12345"
enterprise_name:"Meta securities"
title:"bouncer"
rate:3500
unit:"per day"

Hi @nexus.saugat26, I’m not sure I understand your question. Are you try to create a relationship between two different records in your indices? If so, Algolia does not work like a relational database. You will need to update each record individually, or you could combine all the fields in one record.

Let me know if I’ve misunderstood your question.

objectID: "12345"
enterprise_name:"Meta Securities"
invoice:111
quotation:41
customers:83
contact:987654321
geoloc:{ lat: "26.78552698", lng: "85.03094429" },
quotation:[{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45678"
},
{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45679"
},
{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45680"
},
]

@cindy.cullen like u said i might combine fields like above. however how can i update quotation id 45680 using algolia using sth like following?

const index = quotation.findIndex(quotation=> quotation.quotation_id==='45680');
quotation[index] = {
title:"bouncer"
rate:3500
unit:"per week"
quotation_id: "45680"
};

only thing i can seek from algolia so far is

export const updateQuotationToIndex = functions.firestore
  .document("quotation/{quotationId}")

  .onUpdate((change) => {
    const newData = change.after.data();
    // const enteprise_id = change.after.data().admin_enterprise_id;

    const objectID = change.after.id;

    return index.partialUpdateObject({
      quotation:{
        operation:"Add",
        value:newData
      }
      objectID,
    });
  });

here it will add another object not replace the object with quotation_id: “45680”

I’m not sure if I fully understand your use case, since you didn’t mention how you initially add the data, but the objectID is the primary key of an object. If you want to update the same object later, you need to use the same objectID as in the initial add. I see there that you are using change.after.id, which is probably the change id, while your local identifier is quotation_id.

A way you can get this to work, while not perfect is to retrieve the objectID before updating:

const results = await index.search('', { filters: "quotation_id:45680" });
const item = results.hits[0];
const objectID = item.objectID;

Then you can use that id for the partial update. This is to note that that does an extra operation, which is avoidable if you have access to the objectID in the update handler

what i have come to conclusion now is that the array of objects i.e. quotation can be updated.
i can do so by retrieving the following object using getOjbect() from the object_id “12345”

let  newData = objectID: "12345"
enterprise_name:"Meta Securities"
invoice:111
quotation:41
customers:83
contact:987654321
geoloc:{ lat: "26.78552698", lng: "85.03094429" },
quotation:[{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45678"
},
{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45679"
},
{
title:"bouncer"
rate:3500
unit:"per day"
quotation_id: "45680"
},
]

then i can use following code

const index = newData.quotation.findIndex(quotation => quotation.quotation_id==='45680');
newData.quotation[index] = {
title:"bouncer"
rate:3500
unit:"per week"
quotation_id: "45680"
};

and then push newData object once again using partialUpdateOjbect

this is the alternative i have found instead of batch update because of limitation of algolia that it cant work like relational database.