Full-text search APIOutdated Content Warning: This content refers to an older version of OpenSpending. See here for information about the next version of OpenSpending and ways to contribute.
OpenSpending supports full-text search as a research tool for everyone who wants to investigate the spending information kept in our database.
It is important to note, however, that search is always performed on individual entries. More abstract concepts (e.g. “all health spending in a country over a given year”) would mostly be the result of adding up many individual entries. If your use case requires that you access such concepts, you may want to look at the aggregation API instead.
Basic call and parameters
Calls will return a set of fully JSON serialized entries, query statistics, and, depending on the other parameters, other data such as facets.
The following parameters are recognized:
qQuery string. Will usually search a composite text field but can be limited to a specific field (i.e. a dimension, attribute, or measure) with
field:value. Boolean operators such as OR, AND, and ±term can also be used.
datasetSpecifies a dataset name to search in. While searching across multiple datasets is supported, this parameter can be used to limit the scope and increase performance. It can be used multiple times or multiple dataset names can be separated with pipe symbols.
categoryThe dataset category can be used to filter datasets by their type, e.g. limiting the output to only transactional expenditure (and excluding any budget items). Valid values include
statsIncludes solr statistics on measures, namely the average, mean, and standard deviations. This is generated through the indexed data and can differ marginally from the results of the aggregator due to floating point inaccuracies. Note that aggregations across datasets with different currencies (or even the same currency across different years) are possible but must be avoided.
filterApply a simple filter of the format
field:value. Multiple filters can be joined through pipes, e.g.
pagePage number for paginated results. Defaults to
pagesizeSize of a page for paginated results. Defaults to
facet_fieldA field to facet the search by, i.e. give all the distinct values of the field in the result set with the count of how often each occurred.
facet_pagesizeWorks analogously to the
pagesizeparameters but applies to facets instead.
expand_facet_dimensionsWhen a compound dimension name is used for a facet, this will return a full representation of this dimension value for each value.
If an error is detected, the system will return a simple JSON response
with a list of
errors describing the fault.
Solr query syntax
OpenSpending uses Apache Solr for full-text indexing. Some search parameters are passed directly to Solr:
Some useful resources to explore the query language of Solr include:
Up: OpenSpending API