没有为 demo.ckan.org 处的资源创建视图

No view created for a resource at demo.ckan.org

曾经 ,我 demo.ckan.org 有另一个问题。

创建资源后,我创建了一个数据存储并更新了一些数据:

POST http://demo.ckan.org:80/api/3/action/resource_create HTTP/1.1
{"help": "http://demo.ckan.org/api/3/action/help_show?name=resource_create", "success": true, "result": {"cache_last_updated": null, "cache_url": null, "mimetype_inner": null, "hash": "", "description": "", "format": "", "url": "http://none", "created": "2015-10-01T06:18:25.471301", "state": "active", "webstore_last_updated": null, "webstore_url": null, "package_id": "51b379eb-a2a4-49d8-89b3-188dafdd0279", "last_modified": null, "mimetype": null, "url_type": null, "position": 0, "revision_id": "75c80743-66a8-49d2-a01f-ad67734386f5", "size": null, "id": "12eab044-7853-4907-9879-872550f1376b", "resource_type": null, "name": "room1_room"}}

POST http://demo.ckan.org:80/api/3/action/datastore_create HTTP/1.1
{"help": "http://demo.ckan.org/api/3/action/help_show?name=datastore_create", "success": true, "result": {"fields": [{"type": "int", "id": "recvTimeTs"}, {"type": "timestamp", "id": "recvTime"}, {"type": "text", "id": "entityId"}, {"type": "text", "id": "entityType"}, {"type": "text", "id": "attrName"}, {"type": "text", "id": "attrType"}, {"type": "json", "id": "attrValue"}, {"type": "json", "id": "attrMd"}], "method": "insert", "resource_id": "12eab044-7853-4907-9879-872550f1376b"}}

POST http://demo.ckan.org:80/api/3/action/datastore_upsert HTTP/1.1
{"help": "http://demo.ckan.org/api/3/action/help_show?name=datastore_upsert", "success": true, "result": {"records": [{"attrType": "centigrade", "recvTime": "2015-10-01T06:18:24.72Z", "recvTimeTs": "1443680304", "attrValue": "26.5", "entityType": "Room", "attrName": "temperature", "entityId": "Room1"}], "method": "insert", "resource_id": "12eab044-7853-4907-9879-872550f1376b"}}

数据在那里,可以通过datastore_search:

检索
curl -s -S -H "Authorization: b4f6cd71-b592-49a3-bb85-9cd5a0f2eb68" "http://demo.ckan.org/api/3/action/datastore_search?resource_id=12eab044-7853-4907-9879-872550f1376b"
{"help": "http://demo.ckan.org/api/3/action/help_show?name=datastore_search", "success": true, "result": {"resource_id": "12eab044-7853-4907-9879-872550f1376b", "fields": [{"type": "int4", "id": "_id"}, {"type": "int4", "id": "recvTimeTs"}, {"type": "timestamp", "id": "recvTime"}, {"type": "text", "id": "entityId"}, {"type": "text", "id": "entityType"}, {"type": "text", "id": "attrName"}, {"type": "text", "id": "attrType"}, {"type": "json", "id": "attrValue"}, {"type": "json", "id": "attrMd"}], "records": [{"attrType": "centigrade", "recvTime": "2015-10-01T06:18:24.720000", "recvTimeTs": 1443680304, "attrMd": null, "attrValue": "26.5", "entityType": "Room", "attrName": "temperature", "entityId": "Room1", "_id": 1}], "_links": {"start": "/api/3/action/datastore_search?resource_id=12eab044-7853-4907-9879-872550f1376b", "next": "/api/3/action/datastore_search?offset=100&resource_id=12eab044-7853-4907-9879-872550f1376b"}, "total": 1}}

尽管如此,demo.ckan.org 说:

There are no views created for this resource yet.

Not seeing the views you were expecting? Click here for more information.

Here are some reasons you may not be seeing expected views:

  • No view has been created that is suitable for this resource
  • The site administrators may not have enabled the relevant view plugins
  • If a view requires the DataStore, the DataStore plugin may not be enabled, or the data may not have been pushed to the DataStore, or the DataStore hasn't finished processing the data yet

我一直在使用 2.2 API,无需创建视图。现在,看来我必须用 2.4 API 创建这样的视图。它是否正确,我必须使用 http://docs.ckan.org/en/ckan-2.4.0/api/index.html#ckan.logic.action.create.resource_view_create 方法?还是仅仅是门户的问题?

这可能是演示服务器的设置方式,我建议使用 API 调用自己创建 resource_view(除非您可以控制服务器并且配置不同)是要走的路。

不会像这样为直接在数据存储中创建的资源数据自动创建视图。创建是由 resource create 触发的,假设那里有一些数据,但是您创建了一个空资源并稍后向其中添加数据。正如另一个答案中所建议的那样,最好的方法是使用 API.