Update of nested object in an index

Hi,

How do I perform update on the object inside a record in an index? For example I have this example.

{
   ShowId: 1,
   ShowTitle: "Home sweetie home",
   Celebrities: [
      {
          CelebrityId: 2,
          CelebrityFullName: "Toni Gonzaga",
          BirthPlace: "Manila",
          CelebrityRole: "Actor"
      },
      {
          CelebrityId: 1,
          CelebrityFullName: "John Lloyd Cruz",
          BirthPlace: "Manila",
          CelebrityRole: "Actor"
      }
   ],
   ShowId: 2,
   ShowTitle: "You are the one",
   Celebrities: [
      {
          CelebrityId: 2,
          CelebrityFullName: "Toni Gonzaga",
          BirthPlace: "Manila",
          CelebrityRole: "Actor"
      },
      {
          CelebrityId: 3,
          CelebrityFullName: "Efren Miller",
          BirthPlace: "Manila",
          CelebrityRole: "Actor"
      }
   ]
}

What if celebrity “Toni Gonzaga” changed Birthplace, how do I change all records with Celebrity “Toni Gonzaga” to its new birthplace?

Thank you!

I don’t think you will be able only send the new BirthPlace. You will need need to send the whole Celebrities object.
Here is the doc about partial updates if you need it: https://www.algolia.com/doc/api-client/php/indexing/#partial-update-objects

Will that be a problem for you?

Hi @julienbourdeau,

Thank you very much for your response!

What I’m figuring out now, is I structured the celebrities object redundantly, we did it because I have a description field in the Celebrities object, which usually take long paragraphs, so I split it per sentence and each sentence is another record in the index.

Each celebrity occurs in many shows, so when the celebrity is actually updated, it has to be updated in show records which are redundantly designed.

Sorry for this question, but should I update the each show containing that celebrity or should I create a new index for the celebrity?

1 Like

@julienbourdeau Is the any solution to @markdaniel_tamayo’s question?

Hi @kames,

All shows must be updated when an actor’s bio is modified. It may result in many operations, although, you can delay them so if you edit multiple actor in the same show, it will only be updated once. Ideally, I’d recommend updating the entire record, not just the celebrities attribute.

Creating a celebrity index is possible, if you want to find celebrities. If you want to find shows based on celebrities, you need to nest celebrities content under show records.

Celebrities can be a very light attribute. You need to decide if it makes sense for your app to be able to find a show based on one actor birth place or if it can be omitted.

Please let me know if that answers your question.

Thank you. Do you recommend this design? Storing all the celebrities under a show and updating the celebrity in all the shows when the celebrity is updated?

Yes this is very typical with Algolia :ok_hand: