Ravers
Ravers

Reputation: 1039

How to query datasets by group with CKAN API?

I have managed to create a query to get datasets by tags. For reference I have the following query:

http://localhost/api/3/action/package_search?fq=tags:(my-first-tag%20AND%20my-second-tag)&rows=2

Now, I need to filter these results by the group also. I added a dataset to a group and can see the group as:

http://localhost/api/3/action/group_list

But how can I add the group to the previous query? I can't seem to find anything that works.

Upvotes: 2

Views: 1104

Answers (1)

Zoran Pandovski
Zoran Pandovski

Reputation: 2342

You can use the filter query (fq) to search using the group name. For e.g to search the datasets that are in the test group

https://demo.ckan.org/api/3/action/package_search?fq=groups:test-group

To include the two fq, we need to make the query like this:

http://localhost/api/3/action/package_search?fq=tags:(my-tag-1%20AND%20my-tag-2)+groups:my-group-1&rows=2

Upvotes: 3

Related Questions