Search code examples
restfiltergetckan

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.


Solution

  • 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