Modifying Unreasonable Query Parameters with INFINI Gateway for Elasticsearch Cluster Protection

This article explains how to use INFINI Gateway to modify unreasonable query parameters, a method also applicable to OpenSearch and INFINI Easysearch.

In previous posts, we covered blocking resource-intensive queries. Some queries are inherently expensive (e.g., fuzzy searches, nested aggregations). Others become problematic due to inappropriate parameter values, such as deep pagination or enabling profile. Instead of outright blocikng, we can adjust these parameters to reasonable values.

Unreasonable Parameters

Unreasonable parameters are essentially those with inappropriate values. Some parameters are necessary but their values cause excessive resource consumpsion; adjusting them suffices. Others are meant for debugging or special scenarios and should be removed or set to false in productino.

For example, the following query has both size and track_total_hits that can be optimized:

GET my_index/_search
{
  "size": 10000,
  "track_total_hits": true,
  "query": {
    "match": {
      "title": "example"
    }
  }
}

Another costly debugging query that should be avoided in production:

GET my_index/_search
{
  "query": {
    "match": {
      "title": "example"
    }
  },
  "profile": "true",
  "explain": true
}

Using the request_body_json_set Filter

The request_body_json_set filter in INFINI Gateway allows modifying field values in JSON request bodies. The gateway configuration below adjusts the problematic parameters:

flow:
  - name: protect_flow
    filter:
      - request_body_json_set:
         path:
          - explain -> false
          - size -> 10
          - track_total_hits -> false
          - profile -> false
      - elasticsearch:
          elasticsearch: main
          max_connection_per_node: 500

Effect of Modification

Before applying the filter, the query contains the original values. After processing through the gateway, the parameters are rewritten to the safe defaults (size: 10, track_total_hits: false, profile: false, explain: false). The gateway automatically logs all requests, making it easy to identify which parameters need adjustment by analyzing the recorded queries. Refer to the official documentation for details on query recording and analysis.

About INFINI Gateway

INFINI Gateway is an open-source, high-performance data gateway designed for search scenarios. All requests pass through the gateway before reaching the backend cluster. It enables index-level rate limiting, query caching, request auditing, and dynamic modification of query results.

Project documentation: https://docs.infinilabs.com/gateway/main/
Source code: https://github.com/infinilabs/gateway

Tags: INFINI Gateway elasticsearch OpenSearch Easysearch query optimization

Posted on Tue, 25 Aug 2026 16:13:48 +0000 by spaggle