# Elasticsearch & OpenSearch Filters > [!NOTE] All filters documented on this page work with both Elasticsearch and OpenSearch. See the > [Elasticsearch & OpenSearch documentation](elasticsearch.md) for setup instructions. For further documentation on filters (including for Eloquent and Doctrine), please see the [Filters documentation](filters.md). > [!WARNING] For maximum flexibility and to ensure future compatibility, it is strongly recommended > to configure your filters via the parameters attribute using `QueryParameter`. The legacy method > using the `ApiFilter` attribute is **deprecated** and will be **removed** in version **5.0**. The modern way to declare filters is to associate them directly with an operation's parameters. This allows for more precise control over the exposed properties. Here is the recommended approach to apply a `MatchFilter` only to the title and author properties of a Book resource. ```php new QueryParameter( properties: ['title', 'author'], // Only these properties get parameters created filter: new MatchFilter() ) ] ) ])] class Book { // ... } ``` > [!TIP] This filter can be also defined directly on a specific operation like > `#[GetCollection(...)])` for finer control, like the following code: ```php new QueryParameter( properties: ['title', 'author'], // Only these properties get parameters created filter: new matchFilter() ) ] )] class Book { // ... } ``` ## Further Reading - Consult the documentation on [Per-Parameter Filters (Recommended Method)](../core/filters.md#2-per-parameter-filters-recommended). - If you are working with a legacy codebase, you can refer to the [documentation for the old syntax (deprecated)](../core/filters.md#1-legacy-filters-searchfilter-etc---not-recommended). ## Ordering Filter (Sorting) The order filter allows to [sort](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html) a collection against the given properties. Syntax: `?order[property]=` Enable the filter: ```php 'order'])] class Tweet { // ... } ``` ```yaml # config/services.yaml services: tweet.order_filter: parent: "api_platform.doctrine.orm.order_filter" arguments: $properties: { id: ~, date: ~ } $orderParameterName: "order" tags: ["api_platform.filter"] # The following are mandatory only if a _defaults section is defined with inverted values. # You may want to isolate filters in a dedicated file to avoid adding the following lines (by adding them in the defaults section) autowire: false autoconfigure: false public: false # config/api/Tweet.yaml App\Entity\Tweet: # ... filters: ["tweet.order_filter"] ``` Given that the collection endpoint is `/tweets`, you can filter tweets by ID and date in ascending or descending order: `/tweets?order[id]=asc&order[date]=desc`. By default, whenever the query does not specify the direction explicitly (e.g: `/tweets?order[id]&order[date]`), filters will not be applied unless you configure a default order direction to use: ```php 'asc', 'date' => 'desc'])] class Tweet { // ... } ``` ### Using a Custom Order Query Parameter Name A conflict will occur if `order` is also the name of a property with the term filter enabled. Luckily, the query parameter name to use is configurable: ```yaml # api/config/packages/api_platform.yaml api_platform: collection: order_parameter_name: "_order" # the URL query parameter to use is now "_order" ``` ## Match Filter The match filter allows us to find resources that [match](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) the specified text on full-text fields. Syntax: `?property[]=value` Enable the filter: ```php $context['filters']['fullName'], 'operator' => 'and', ]; $requestBody['query']['constant_score']['filter']['bool']['must'][0]['match']['full_name'] = $andQuery; return $requestBody; } } ```