I have a object with this data.
{
_id:"5ec6cdf648fdd1678c6f20a6",
title:"Abc",
objectID:"35922720"
}
How can I delete data by _id
?
Note, this is a custom property and not the standard Algolia property objectId
.
I have a object with this data.
{
_id:"5ec6cdf648fdd1678c6f20a6",
title:"Abc",
objectID:"35922720"
}
How can I delete data by _id
?
Note, this is a custom property and not the standard Algolia property objectId
.
There are only two ways to delete items in an Algolia index:
objectId
. More here.Based on this, you can delete an object directly using "Delete by Query" if it can be selected by a supported query option. If it cannot be deleted using Delete by Query, then you would need to retrieve the objects and delete them by the Algolia standard objectId
property.
In this scenario, _id
is a custom string property so you cannot use "Delete by Query", but would need to perform a select query first to retrieve the object's standard objectId
property.
If you wanted to use Delete By Query and could modify the index, you could convert _id
to a numeric field. Your id is a hexadecimal number in string representation so one approach could be to convert this to a decimal representation.
For example, if your object's custom _id
property was numeric like the following, you could delete it using "Delete by Query".
{
_id:12345,
title:"Abc",
objectID:"35922720"
}
The Delete By Query params would be:
{
"params":"numericFilters=_id=12345"
}
See more on Numeric Filters here.
In the future, you may able to delete by a hexadecimal number as hexadecimal is supported in JSON5 but it would still need support by Algolia and a change in representation in your index. In this scenario, your object would look like:
{
_id:0x5ec6cdf648fdd1678c6f20a6,
title:"Abc",
objectID:"35922720"
}