본문 바로가기
카테고리 없음

알고리아 Sending And Managing Data(2-12)

by dev_caleb 2022. 3. 1.
728x90

Incremental Updates(증가 업데이트)

https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/how-to/incremental-updates/

 

Incremental updates | Algolia

How to keep your data in sync with Algolia.

www.algolia.com

 

Once you’ve first indexed your data, you need to keep your index up to date as the data changes.

데이터를 처음 인덱싱한 후에는 데이터가 변경될 때 인덱스를 최신 상태로 유지해야 합니다.

One way of doing so is via incremental updates, by tracking changes and forwarding them to Algolia. Whenever you add, edit, or delete data from your source, you want to update the corresponding records so they reflect the latest state of your data.

이를 위한 한 가지 방법은 증분 업데이트를 통해 변경사항을 추적하여 알고리아에 전달하는 것이다. 원본에서 데이터를 추가, 편집 또는 삭제할 때마다 데이터의 최신 상태를 반영하도록 해당 레코드를 업데이트할 수 있습니다.

 

Tracking each record with a unique identifier(고유 id로 각각의 레코드 추적하기)

To perform incremental updates, you need to declare a unique identifier for each record so you can track what data matches what record. This identifier should map to a “key” you store on your side. For instance, if you’re selling books and you have one Algolia record per book, you could use the ISBN.

You need to store the unique identifier in the objectID attribute so you can leverage it to perform updates or deletions.

증분 업데이트를 수행하려면, 어떤 데이터가 어떤 레코드와 일치하는지 추적할 수 있도록 각 레코드에 대해 고유한 식별자를 선언해야 합니다. 이 식별자는 사용자가 측면에 저장한 "키"에 매핑되어야 합니다. 예를 들어 책을 팔고 있는데 한 권에 하나의 알골리아 음반이 있다면 ISBN을 사용할 수 있습니다.
고유 식별자를 객체에 저장해야 합니다.ID 속성을 사용하여 업데이트 또는 삭제를 수행할 수 있습니다.

 

 

 

Updating records(레코드 업데이트)

There are two ways to incrementally update records in Algolia:(알골리아의 레코드를 점진적으로 업데이트하는 방법에는 두 가지가 있습니다.)

  • Fully replacing the old record with a new one(이전 레코드를 새 레코드로 완전히 교체)
  • Updating only a subset of the existing record with the changed data(변경된 데이터로 기존 레코드의 하위 세트만 업데이트)

Replacing the old record(오래 된 레코드 교체하기)

When saving a record in Algolia, if a record with the specified objectID already exists in the index, the engine replaces it. You can replace an existing record by using the method and specifying the objectID. This technique is useful when you’re updating data in a single place in your system, or when you don’t know what changed.

Algolia에서 레코드를 저장할 때 지정한 개체를 가진 레코드가 있는 경우ID가 인덱스에 이미 있으며 엔진에서 레코드를 바꿉니다. 메소드를 사용하고 objectID를 지정하여 기존 레코드를 바꿀 수 있습니다. 이 기술은 시스템의 한 곳에서 데이터를 업데이트할 때 또는 변경된 내용을 모를 때 유용합니다.

 

Note that every record contains the objectID of the record to delete. 모든 레코드에는 삭제할 레코드의 objectID가 포함되어 있습니다.

 

Updating a subset of the record(레코드 하위 집합 업데이트)

Sometimes, you may want to update a subset of the attributes of a record and leave the rest untouched. This is useful when you update data in multiple places. With the books example, you may have two different systems to handle metadata and to manage stock, both updating the index, with no knowledge about the rest of the data.

For this, you can use the partialUpdateObjects method and only pass the changed data. Anything you don’t specify remains untouched.

레코드 특성의 일부만 업데이트하고 나머지는 그대로 두는 경우가 있습니다. 이것은 여러 장소에서 데이터를 업데이트할 때 유용합니다. 예제를 보면 메타데이터를 처리하고 재고를 관리하는 두 개의 서로 다른 시스템이 있는데, 둘 다 인덱스를 업데이트하지만 나머지 데이터에 대한 지식이 없을 수 있습니다.
이 경우 partialUpdateObjects 방법을 사용하고 변경된 데이터만 전달할 수 있습니다. 당신이 명시하지 않은 것은 손대지 않은 채로 남습니다.

 

const objects = [{
  firstname: 'Jimmie',
  objectID: 'myID1'
}, {
  firstname: 'Warren',
  objectID: 'myID2'
}];

index.partialUpdateObjects(objects).then(({ objectIDs }) => {
  console.log(objectIDs);
});

Deleting records#

Whenever you delete data in your data source, you can delete the corresponding record from Algolia with deleteObjects.

index.deleteObjects(['myID1', 'myID2']).then(({ objectIDs }) => {
  console.log(objectIDs);
});

Note that every record contains the objectID of the record to delete.

Delete by query

Sometimes, you may need to delete all records matching a certain filter. Back to the book example, if you stop selling books from a specific publisher, you might want to delete all records matching this publisher in your index. To do this, you can use the deleteBy method.

The deleteBy method is an expensive operation for the engine. For better performance, use the deleteObjects method instead.

 

index.deleteBy({
  filters: 'category:cars',
  aroundLatLng: '40.71, -74.01'
}).then(() => {
  // done
});

Any attribute you’re using to delete by needs to be in your searchableAttributes.

 

 

 

 

 

 

 

728x90