CSW CQL date query syntax (KVP)

Hi all, I’m looking for a bit of help constructing a query against a GeoNetwork CSW server.

One aspect: with the new OGC website, I can’t find the CQL 1.1 spec. It’s all very well promoting the new ones (in this case CQL 2 as used in OGC API Features), but there are thousands of implementations out there which still implement the old ones.

But my actual question is how to constrain the results by date, so I only get back the records modified since a particular date (e.g. the data I last ‘harvested’ from that server).

My preference is to use the KVP approach.

I’ve tried a variety of things like:

AND%20modified%20after%20%272025-01-01T00:00:00Z%27

AND%20modified%20after%202025-01-01T00:00:00Z

(I’ve tried 20250101, and a date without a time, and AFTER)

I get a variety of exception results, mostly along the lines of

<ows:ExceptionText>Error during CQL to Filter conversion : org.geotools.filter.text.cql2.CQLException: Encountered “after '2025-01-01T00:00:00Z'” at line 1, column 27. Was expecting one of: “(” … “:” … … “.” … … “like” … “is” … “exists” … “does-not-exist” … “tequals” … “before” … “after” <DATE_TIME> … “after” … “during” … “between” … … … … … … … Parsing : anyText='OGL’AND modified after ‘2025-01-01T00:00:00Z’.</ows:ExceptionText>

so it’s expecting “after”, but how to express the <DATE_TIME>, if not as an ISO 8601 string?

I get the same response from two different organisation’s GeoNetwork instances; one is running 4.2.9 the other is running 4.4.something

Hi,

Your expression of the date was right I believe. The “after” operator and “modified” keywords do not seem to be supported by GeoNetwork, I could get a similar query to work like so:

&constraintLanguage=CQL_TEXT&constraint_language_version=1.1.0&constraint=changeDate%20>=%20%272025-01-01T00:00:00Z%27

Let me know how that works for you!

Thanks for the quick input. It seems to move my issue “forward” a bit, but for me it now gives a different error - rather than an error parsing from CQL to JSON, I now get a Java crash /JSON parsing error reported:

java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 92)): expected a valid value (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’) at [Source: (String)“{ “bool”: { “must”: [ { “range” : { “changeDate” : { “gte” : "2025-01-01T00:00:00Z" } } },{“query_string”: { “fields”: [“any.*”], “query”: “OGL” }} ] ,“filter”:{“query_string”:{“query”:”(op0:(1) ) AND (isTemplate:n) AND (draft:n OR draft:e)“}}}}”; line: 6, column: 26]

So, the %27 around the date gets parsed to " and the JSON parser doesn’t like the escape character in front of the quotation mark.

That was against my 4.2.9 server (https://osmetadata.astuntechnology.com/geonetwork/srv/eng/csw).

Against a colleague’s 4.4 (at https://metadata.bgs.ac.uk/geonetwork/srv/eng/csw), I can get one record returned (which may well be a true result - and I get more if I give an earlier date)

I think this relates to CSW GetRecords filter to get last modified records - JsonParseException · Issue #8034 · geonetwork/core-geonetwork. That made me experiment with my timestamp in POSIX time (milliseconds since 1970-01-01 - which does give me usable results. But is not something an approach I want to recommend my customers use: so, perhaps it is time to upgrade.

Neither of us advertise “changeDate” as a queryable - but that is a separate issue & needs fixing elsewhere!