Basically I want to combine 2 cql filters of the same layer and output the result on my geoserver layer. It is similar to this SQl query (my case using PostgreSQL):

select * from table1 where val = 'a'
union all  // union all means keeps duplicate
select * from table1 where val = 'b'  

I tried using the cql_filter as below but didnt work

cql_filter="val"='a' union "val"='b'

I dont find the cql_filter union function (not union of geometries) in https://docs.geoserver.org/stable/en/user/filter/function_reference.html as well. What is the proper way to use UNION ALL likewise the SQL query in GeoServer cql filter?

  • Could it be done in PostGIS first, then query off of the view of the union? Jul 16, 2020 at 3:06
  • @DPSSpatial does that mean I have to create another layer? I prefer to just use the initial layer and filter the features
    – gameon67
    Jul 16, 2020 at 3:16
  • I guess I don't understand why you're querying the same layer twice and trying to UNION both results versus multiple WHERE on the layer once? Jul 16, 2020 at 16:44
  • @DPSSpatial yeah I didnt realize that simple OR can be used for this case
    – gameon67
    Jul 16, 2020 at 23:32
  • Excellent!! Glad that will work. Jul 17, 2020 at 1:19

2 Answers 2


You can combine two filters using or (or and) so your query becomes

cql_filter="val"='a' or "val"='b'
  • that would work (and probably be quicker) in Postgis too
    – Ian Turton
    Jul 16, 2020 at 7:25
  • Clever, I over-complicated things and didn't realize that single OR can be used instead of combining 2 filters / queries
    – gameon67
    Jul 16, 2020 at 23:33

Below solution works but probably not the best.

I made a layer group by combining multiple of same layer instead of just 1 layer


Then use the cql filter as below


Here's the complete URL sample


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.