[id='ref-configuring-filters-{context}']
= Defining filters

Filters in Kroxylicious can be defined globally with `filterDefinitions`, applied by default using `defaultFilters`, or customized for specific virtual clusters. 
The following example shows how these elements work together flexibly:

[id='con-filterDefinitions-defaultFilters-{context}']
.Example configuration showing global filter definitions applied as defaults and to virtual cluster
[source,yaml]
----
filterDefinitions:
  - name: encryption
    type: RecordEncryption
    config:
      # ...
  - name: validation
    type: RecordValidation
    config:
      # ...
  - name: special-encryption
    type: RecordEncryption
    config:
      # ...
defaultFilters:
  - validation
  - encryption
virtualClusters:
  - name: my-proxy-with-default-filters
    # ...
  - name: my-proxy-with-custom-filters
    filters:
      - validation
      - special-encryption
    # ...
# ...
----

* The order of definitions in `filterDefinitions` does not matter.
* Each filter definition in `filterDefinitions` must have a unique `name`, but you can have multiple definitions with the same type and different configurations (as with `encryption` and `special-encryption` in the example).
* The order of `defaultFilters` determines the sequence in which the filters are applied to incoming client requests. In the example, records are first validated and then encrypted.
* The `defaultFilters` are used for all virtual clusters which don't define their own `filters`, such as `my-proxy-with-default-filters`.
* The `defaultFilters` property is optional. It is useful when all virtual clusters must use the same filters. There's no need to specify it if all virtual clusters have specific `filters` defined.
* When a virtual cluster has defined `filters`, like `my-proxy-with-custom-filters`, then those filters are used instead of the `defaultFilters`.
* When using `defaultFilters` or a virtual cluster's `filters` to reference a filter definition, you must define a filter with the corresponding name in `filterDefinitions`.

