Aggregation 504 bad gateway

When I use script to do aggregation and want to find two documents with the same fields in es, 504 bad gateway.
Maybe it is caused by too much data. Is there any solution?
I used partition.

  "size": 0,
  "aggs": {
    "duplicateCount": {
      "terms": {
        "script": {
          "source":"doc['id'].value ",
          "lang": "painless"
        "min_doc_count": 2,
        "size": 10,
        "include": {
          "partition": 0,
          "num_partitions": 10
      "aggs": {
        "duplicateDocuments": {
          "top_hits": {
            "size": 10


        <title>504 Gateway Time-out</title>
            <h1>504 Gateway Time-out</h1>

Sounds like an error message from nginx not elasticsearch.

Thank you very much.

Nginx error is caused by a timeout.
How can I make this request return a partial result quickly?

May be have a look at or increase the nginx timeout?

Why are you using a painless script to run a terms aggregation? Why not a terms agg on the id field?

Thank you very much. I'm just giving a simple example here. In our real use scenario, the type is an array. It is more complicated to sort each value in the array for aggregation, so script is used.

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