CKAN: delete a list of records within the DataStore in a single query

南笙酒味 提交于 2019-12-11 05:38:52

问题


NOTE: My original problem is to delete all the records except for the last N ones, but guessing such a thing is impossible with CKAN API, I've come up with the following solution:

  1. To get the total ammount of records using datastore_search.
  2. To get the ID of the first record in the previous search.
  3. To obtain the IDs of all the records from the first record ID to total-N.

So, my question is: how to delete all the identified IDs in a single query? I've tried the following:

$ curl -X POST "http://demo.ckan.org/api/3/action/datastore_delete" -d '{"filters":{"_id":1,"_id":2,"_id":3},"force":"true","resource_id":"a43bfb04-7a8b-4624-a06a-25f4165e5b2a"}' -H "Authorization: xxx"
{"help": "http://demo.ckan.org/api/3/action/help_show?name=datastore_delete", "success": true, "result": {"filters": {"_id": 3}, "resource_id": "a43bfb04-7a8b-4624-a06a-25f4165e5b2a"}}

But only the record regarding the last ID (3) was removed.

Of course, an array did not work as well:

$ curl -X POST "http://demo.ckan.org/api/3/action/datastore_delete" -d '{"filters":[{"_id":1},{"_id":2},{"_id":3}],"force":"true","resource_id":"a43bfb04-7a8b-4624-a06a-25f4165e5b2a"}' -H "Authorization: xxx"
{"help": "http://demo.ckan.org/api/3/action/help_show?name=datastore_delete", "success": false, "error": {"__type": "Validation Error", "filters": ["filters must be either a dict or null."]}}

Any idea? Or should I perform a query for each record aimed to be deleted?


回答1:


Auto-answering. After trying several combinations, I've found this works:

$ curl -X POST "http://demo.ckan.org/api/3/action/datastore_delete" -d '{"filters":{"_id":[1,2]},"force":"true","resource_id":"a43bfb04-7a8b-4624-a06a-25f4165e5b2a"}' -H "Authorization: xxx"

I.e. a dictionary has to be sent with a single (key,value) pair, the _id and an array of values for the _id, respectively.



来源:https://stackoverflow.com/questions/41227226/ckan-delete-a-list-of-records-within-the-datastore-in-a-single-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!