maxBodyLength limit

log:

callAsCurrentUser:scroll|{"scrollId":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAA_Q-QWOHdpMWswdlRUamlNX0hoVDBWUFowZw==","scroll":"1m","headers":{"x-kbn-domain":"******","x-kbn-user":"******"}};;undefined
{"type":"log","@timestamp":"2024-01-16T08:06:12Z","tags":["license","debug","xpack"],"pid":13,"message":"Calling [data] Elasticsearch _xpack API. Polling frequency: 30001"}
{"type":"error","@timestamp":"2024-01-16T08:06:08Z","tags":[],"pid":13,"level":"error","error":{"message":"Request body larger than maxBodyLength limit","name":"Error","stack":"Error: Request body larger than maxBodyLength limit\n    at RedirectableRequest.write (/root/kibana-7.4.2-SNAPSHOT-linux-x86_64/node_modules/follow-redirects/index.js:97:24)\n    at RedirectableRequest.end (/root/kibana-7.4.2-SNAPSHOT-linux-x86_64/node_modules/follow-redirects/index.js:116:8)\n    at dispatchHttpRequest (/root/kibana-7.4.2-SNAPSHOT-linux-x86_64/node_modules/axios/lib/adapters/http.js:235:11)\n    at new Promise (<anonymous>)\n    at httpAdapter (/root/kibana-7.4.2-SNAPSHOT-linux-x86_64/node_modules/axios/lib/adapters/http.js:18:10)\n    at dispatchRequest (/root/kibana-7.4.2-SNAPSHOT-linux-x86_64/node_modules/axios/lib/core/dispatchRequest.js:59:10)\n    at process._tickCallback (internal/process/next_tick.js:68:7)"},"url":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":"?fields=title&per_page=10000&type=index-pattern","query":{"fields":"title","per_page":"10000","type":"index-pattern"},"pathname":"/api/saved_objects/_find","path":"/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern","href":"/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern"},"message":"Request body larger than maxBodyLength limit"}

version: 7.4.2

desc: I modified the SavedObjectsRepository.find() method to obtain a large amount of index-patterns(more than 20K pieces) through scrolling query, but i got the error above. I'm curious how to increase maxBodyLength in Kibana.

Hi @fdranger,

Welcome to the community! Can you share the query, code snippet or action that is triggering this error?

Just a heads up that version 7.4.2 is past EOL so we would recommend upgrading if you can.

Let us know!

1 Like

Thank you!
This is the code snippet

repository.ts:

async find<T extends SavedObjectAttributes = any>({
  search,
  defaultSearchOperator = "OR",
  searchFields,
  hasReference,
  page = 1,
  perPage = 20,
  sortField,
  sortOrder,
  fields,
  namespace,
  type
}: SavedObjectsFindOptions): Promise<SavedObjectsFindResponse<T>> {
  
  ยทยทยทยทยทยท
  ยทยทยทยทยทยท

  let response = await this._callCluster("search", esOptions);

  if (response.status === 404) {
    // 404 is only possible here if the index is missing, which
    // we don't want to leak, see "404s from missing index" above
    console.log("warn", `Index not found: ${esOptions.index}`);
    return {
      page,
      per_page: perPage,
      total: 0,
      saved_objects: []
    };
  }
  const hitsTotal = response.hits.total;
  let hitsLength = response.hits.hits.length;

  let hits = response.hits.hits;

  if (hitsTotal > hitsLength) {
    while (hitsLength > 0) {
      const scrollId = response._scroll_id;
      response = await this._callCluster("scroll", {
        scrollId,
        scroll: "1m"
      });
      hitsLength = response.hits.hits.length;
      hits = hits.concat(response.hits.hits);
    }
  }
  console.log(`hits total: ${hits.length}`);

  return {
    page,
    per_page: perPage,
    total: response.hits.total,
    saved_objects: hits.map((hit: RawDoc) => this._rawToSavedObject(hit))
  };
}

BTW there is a proxy between Kibana and ES for filtering and forwarding requests.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.