0

while running script in elastic search, I got 504 Gateway timeout error.

 {
      "query": {
        "bool": {
          "filter": {
            "script": {
              "script": " doc['creted_date'].date.getMonthOfYear() == 12 "
            }
          }
        }
      },
      "aggs": {
        "test": {
          "date_histogram": {
            "field": "creted_date",
            "interval": "month",
            "format": "MMM"

          },
          "aggs": {
            "cost": {
              "sum": {
                "field": "cost"
              }
            }
          }
        }
      }
    }

Error result :

 {
      "statusCode": 504,
      "error": "Gateway Time-out",
      "message": "Client request timeout"
    }

whenever I am running this script over index having small number of documents , it gives perfect output. but on index having large number of documents , it gives above error.

Can we manually set the timeout for request in elastic search ? or Is there any other solution for this problem ?

kavi
  • 172
  • 1
  • 14

2 Answers2

-1

Try this.

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "lang": "expression",
          "script": "doc['creted_date'].getMonth() == month-1",
          "params": {
            "month": 12
          }
        }
      }
    }
  }
}
Ashwani Shakya
  • 419
  • 4
  • 11
-1

Try this for Elasticsearch 6.x.

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": {
            "source":  "doc['created_on'].date.getMonthOfYear() == params.month",
              "params": {
                "month": 5
              }
          }
        }
      }
    }
  }
}
Ashwani Shakya
  • 419
  • 4
  • 11
  • 1
    I am not asking for the query. My query is perfectly working for the index having small no of documents. But the problem is timeout. Is there any configuration we need to do in elastic search ? – kavi Sep 25 '18 at 04:54
  • It's not what kavi was asking about. – Petr Aleksandrov Apr 26 '22 at 17:54