Welcome to TERN Knowledge Base

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

Search queries can be created manually or by building a query using the query generator within the EcoPlots portal search page.

Search queries are independent of the tools that are used for sending the query request. For example, the same query body can be used with a request written in cURL, python, postman, R, or another programming language.

Remember that all data endpoints allow filtering!

The query parameter in the request body allows the data requested from any endpoint to be filtered according to the parameters specified. For example:

  • retrieve only sites which contain a feature of interest (FOI), such as “plant occurrence”

  • retrieve only observations which contain a parameter (ie. “basal area”)


Understanding EcoPlots data queries

One of the strengths of EcoPlots is its powerful query system. Data are stored as atomic elements (observations) allowing to filter by 0 to many facets.

Before the user starts to define queries, it is important to understand how the underlying system has been built. Values for every search category store a URI (Uniform Resource Identifier), instead of any human-readable value. Within EcoPlots, this URI is actually a resolvable URL that identifies a unique concept or instance of a class.

"http://linked.data.gov.au/dataset/ausplots" is the identifier of “ausplots” in TERN Surveillance Monitoring (a single instance of the Dataset class)

"http://linked.data.gov.au/def/tern-cv/b311c0d3-4a1a-4932-a39c-f5cdc1afa611"is the identifier of “plant occurrence” (within the Concept class of the Concept Scheme “Feature types”).

The RDF data model (RDF - Semantic Web Standards (w3.org)) used in Ecoplots offers multiple benefits. Because a URI is a unique and immutable identifier for a specific concept, we can easily modify the vocabulary by changing the label, the description or any other property of the concept without having to update the data.

The only drawback to using URIs is that they are usually not human readable. However, all our URIs are resolvable using the HTTP protocol, meaning that you can paste the URI into your browser and retrieve all the details of the element.


There are several different ways you can discover our vocabularies (the possible values in queries):

  1. Inspecting the TERN vocabularies, then use the vocabulary URI of interest

  2. Using the /discover/{field} endpoint. This endpoint returns a set of “key: value” (consisting of a label and URI) entries with all the possible values for every facet.

  1. Using the Ecoplots Portal to discover data, then set use appropriate settings to create a query with the API code generator. It can then be used in your API request.
    For more information on about the code generator, see EcoPlots API - autogenerating queries.

The filter query must be sent in the request body (content type JSON) along with any pagination parameters.


Examples of valid queries

Each of the below examples are syntactically valid ways to write a query requests for the EcoPlots API. All queries must contain a query (even though it may be empty).

"query": {
    "dataset": [
        "http://linked.data.gov.au/dataset/ausplots"
    ]
}
{
    "page_number": 1, 
    "page_size": 50, 
    "query": {
        "dataset": [
            "http://linked.data.gov.au/dataset/ausplots"
        ]
    }
}
"query": {
    "feature_type": [
        "http://linked.data.gov.au/def/tern-cv/b311c0d3-4a1a-4932-a39c-f5cdc1afa611"
    ]
}
"query": {
    "observed_property": [
        "http://linked.data.gov.au/def/tern-cv/0bbd7fcd-0782-4efc-96e6-1f0f7669c655"
    ]
}
{
    "page_number": 1,
    "page_size": 50,
    "query": {}
}
{
    "query": {}
}

Common query syntax errors

If a query includes pagination, both the page_number and the page_size parameters must be included.

Example of an invalid request.

This request is invalid due to only including the page_number. The page_number has not been defined.

{
    "page_number": 1,
    "query": {}
}

Example of an invalid request.

This request is invalid as the request body is empty. At a minimum, requests must contain a query.

{}

Example of an invalid request.

This request is invalid as the request body is empty. At a minimum, requests must contain a query.

{
    "page_number": 1,
    "page_size": 50
}

Facets a query object

Probably need a link to the index of possible query bodies.

Notice that all values (even if it is 1 single value) must be enclosed between square brackets.

Valid query bodies

In these two examples, each value (in the first example http://linked.data.gov.au/dataset/ausplots and in the second example both http://linked.data.gov.au/dataset/ausplots and http://linked.data.gov.au/dataset/corveg) is enclosed within double quotations.

In the second example, the values are separated by a comma and both values are enclosed within square brackets [].

"dataset": [
    "http://linked.data.gov.au/dataset/ausplots"
]
"dataset": [
    "http://linked.data.gov.au/dataset/ausplots",
    "http://linked.data.gov.au/dataset/corveg"
]

Invalid query bodies

The first example is invalid as there are no enclosing square brackets [].

The second example is not technically invalid, however it will yield no results as the dataset list empty.

"dataset": "http://linked.data.gov.au/dataset/ausplots"
"dataset": []
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.