cedadev / search-futures

Future Search Architecture
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

What Common Query Language filters work? #149

Open Mahir-Sparkess opened 2 years ago

Mahir-Sparkess commented 2 years ago

Working Filter Examples

Using the PySTAC client on stac-fastapi-elasticsearch.

api = Client.open("http://127.0.0.1:8000")

Tested working filters using the following CQL formats with a variety of queries.

CQL2 Text filters

cql-text is the default filter format used by stac-fastapi-elasticsearch. So far it can only be done with a GET /search

Useable comparators: =, <=, >=, <>

01. Single facet search:

res = api.search(
    method='GET',
    filter="source_id = 'UKESM1-0-LL'"
)

matched: 84156

02. Multi facet search:

res = api.search(
    method='GET',
    filter="source_id = 'UKESM1-0-LL' and activity_id = 'AerChemMIP'"
)

matched: 23200

CQL2 JSON filters

This filter language allows for POST /search

Quite don't understand the PySTAC tutorials for CQL filters, they do not seem to parse correctly with the PyGeoFilter package used by STAC FastAPI. The following examples may not be the standard, while the results are correct.

01. Single facet search

res = api.search(
    filter={
        "eq": [{"property": "activity_id"}, "AerChemMIP"]
    }
)

matched: 84156

02. Multi facet search

res = api.search(
    filter={
        "and": [
            {"eq": [{"property": "source_id"}, "UKESM1-0-LL"]},
            {"eq": [{"property": "activity_id"}, "AerChemMIP"]},
        ]
    },
    filter_lang="cql2-json"
)

matched: 23200

Notes

Datetime filter

A datetime query in a CQL filter does not work due to any datetime queries bypassing the query-set construction in stac-fastapi-elasticsearch. This is because the CQL filter is translated after the temporal query. The datetime parameter in the client however does work alongside the filter parameter, just not inside a cql filter query.