GeoNode ad-hoc API¶
GeoNode provides a JSON API which currently supports the GET method. The API is also used as main search engine.
GeoNode provides some endpoints and filtering.
- “/api/base” query on the ResourceBase table and returns combined results of Maps, Layers Documents and Services
- “/api/layers” query the Layer table
- “/api/maps” query the Map table
- “/api/documents” query the Document table
- “/api/groups” query the GroupProfile table (which contains the Groups)
- “/api/profiles” query the Profile table (which is the geonode authentication table)
- “/api/categories” query the Category table
- “/api/keywords” query the Tag table
- “/api/featured” query the ResourceBase table by limiting the items to the ones flagged as “featured” (listed in home page)
The API allow filtering by adding Django style model filters to the URL.
As an example, filtering by title corresponds to a URL like “/api/layers?title__contains=grid” It’s also possible to filter by related tables like “/api/layers?keywords__slug__exact=the-keyword”
There are many possible filter, refer to the django filters guide.
API limit and pagination¶
It’s possible to limit the number of the results returned by the API by adding a limit parameter like “/api/layers?limit=10” It’s also possible to specify an offset so that the first results will not be returned (together with the limit this makes a pagination logic), “/api/layers?offset=5”
So a query like “/api/layers?offset=5&limit=10” will return 10 results starting from the 6th found in the database.
You can configure how many results will be lists per page on the client (in the list pages and search page) by changing this line https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L643
And you can set the amount of data returned by default from the API (if the limit parameter is not set), the default is 0 which means no limit https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L646
Searching with Haystack¶
GeoNode is ready to use a complete full text search engine. Note that haystack will be used only on the base, layers, maps and documents API.
Once activated the full text API is reachable by appending “search” to the URL, for example “/api/base/search?limit=0&offset=0”
Although the backend type is not mandatory, we suggest (for simplicity) to use Elasticsearch:
To activate the search backend make sure that you have a running instance of Elasticsearch, then uncomment the following line in the geonode settings:
And activate the search through the settings at the line:
Also uncomment and correct the address of Elasticsearch if needed: https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L612 https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L619
You can do some more customizations like:
- should the search skip the permissions filtering? https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L609
- should the search update the facets counts on every search you make or keep the standard behavior? https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L611
- How many results should the backend return by default? https://github.com/GeoNode/geonode/blob/master/geonode/settings.py#L620