Filter aggregation in Elasticsearch works by first applying a filter condition to select only documents that match. Then, it performs aggregations like sum or average only on those filtered documents. For example, filtering documents where status is 'sold' and summing their price fields. The execution steps are: start query, apply filter, run aggregation on filtered docs, and return results. Variables like doc_count track how many documents matched the filter. If no documents match, aggregation results reflect zero or null values. Changing the filter changes which documents are included and thus changes aggregation results.