An issue arose when executing a script in elastic search, resulting in a gateway timeout error

Encountered a 504 Gateway timeout error while executing a script in elastic search.

 {
      "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"
    }

When executing this script on an index with a small number of documents, it works fine. However, on an index with a large number of documents, the above error is encountered.

Is there a way to manually adjust the request timeout for elastic search or are there any other solutions to address this issue?

Answer №1

If you are using Elasticsearch version 6.x, consider implementing the following query:

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": {
            "source":  "doc['created_on'].date.getMonthOfYear() == params.month",
              "params": {
                "month": 5
              }
          }
        }
      }
    }
  }
}

Answer №2

Give this a shot.

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "lang": "expression",
          "script": "doc['created_date'].getMonth() == month-1",
          "params": {
            "month": 12
          }
        }
      }
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Upgrading Elastic search from version 1.1.0 to 1.6 is causing an issue where an EsRejectedExecutionException exception is

After upgrading ES from version 1.1.0 to 1.6, I encountered a new issue where around 5% of the calls were throwing an EsRejectedExecutionException, something that never occurred with ES 1.1.0. Although all configurations remained unchanged during the upgra ...

Is it possible to manage the form submission in React after being redirected by the server, along with receiving data

After the React front-end submits a form with a POST request to the backend, the server responds with a JSON object that contains HTML instead of redirecting as expected. How can I properly redirect the user to the page received from the server? For inst ...

Creating a circle in SVG that cannot be scaled using Javascript

I'm working on a map project using JavaScript and SVG for drawing the lines. One feature I'd like to implement is the ability to search for a specific road, and if found, display a circle on the map. I understand how to draw a circle in SVG, bu ...

Utilize Material UI's Datagrid or XGrid components to customize the rendering

There is a section from Material UI discussing renderHeader in the DataGrid and Xgrid components. https://material-ui.com/components/data-grid/columns/#render-header The documentation describes how to add additional content to the header, but what if I w ...

Is it more advantageous to pass a value as a prop to a child component, or should the child component retrieve it from Redux instead?

In my scenario, there are two components called <Parent> and <Child>. The <Parent> component is connected to a Redux state property named prop1 using the mapStateToProps() function. Now, I also need the <Child> component to have acc ...

Discovering the identical element within the ajax response

The following section is being targeted: var obj = $(this).parent().find('a'); // $(this) is a <UL> inside a <DIV>, but there can be multiple DIV>ULs on the page After that, I retrieve some HTML using $.ajax(). This HTML corres ...

JavaScript parsing error occurred

Encountering a parsing error in my JavaScript code when deploying Firebase functions. The error mentions an unexpected token, indicating there might be a character out of place. I've been stuck on this issue for weeks now. Any assistance would be grea ...

What is preventing this Javascript from running in Firefox and Chrome?

I recently encountered an issue with some Javascript code that functions correctly in Internet Explorer, but fails to work on Mozilla Firefox or Google Chrome. Any insights as to why this might be the case? function returnData(strCode,strProgramCode,strNa ...

Construct a string by combining the elements of a multi-dimensional array of children, organized into grouped

My task involves manipulating a complex, deeply nested array of nodes to create a specific query string structure. The desired format for the query string is as follows: (FULL_NAME="x" AND NOT(AGE="30" OR AGE="40" AND (ADDRESS ...

The functionality of .map() in Javascript is non-existent

I am completely new to this community (and JavaScript is also new for me), so I apologize in advance for asking some very basic questions. I have an HTML page with various images, all of which share a common class. After using getElementsByClassName, I obt ...

deciphering JSON objects based on specific keys

Struggling to complete a seemingly straightforward task has left me feeling frustrated. In the header of my HTML page, I have an external car dealer API being called. At the bottom of the page, there is another external .js file containing a series of if- ...

Continue running the ajax request repeatedly until it successfully retrieves results

At the moment, I am using a basic ajax call to retrieve data from our query service api. Unfortunately, this api is not very reliable and sometimes returns an empty result set. That's why I want to keep retrying the ajax call until there are results ( ...

Obtaining the chosen options from a dropdown menu

I am facing an issue with retrieving values from dropdown menus on a webpage that are used to filter a list. Despite trying various methods, I am not getting any values returned in my function. Here is what I have attempted: - var browserVal= document.ge ...

What steps do I need to take to build something similar to this using AngularJS?

Struggling with understanding the concepts of AngularJs. How can I create textfields and animations like the ones in this example using AngularJS? I've tried exploring directives, but it's not quite clicking for me. I've attempted to follow ...

The 'property find' is not present in the type Posts[]

Below is the interface I have designed: export interface Post { _id: string; admin: Admin; comments: PostComment[]; createdAt: Date; modified: boolean; text?: string; desc?: string; photoPath?: string; } However, when tryi ...

The interconnected layers of Callback Scope in AngularJS and the overarching rootScope concept

I've been working on an Angular controller to fetch records from a database and display them in a calendar. However, I'm facing an issue where the events array is returning empty. I tried using $rootScope.events as a workaround but encountered an ...

An efficient JavaScript regular expression pattern that allows for both alphanumeric and special characters

Looking for a javascript regex that allows alphanumeric and special characters exclusively. The following regex was attempted but did not work: /^(?!.*(<|>)).*[a-zA-Z0-9 \\\\@!#$%^&*()_+-={}:;'\",.?|\[\&bs ...

Click to refresh a different component in ReactJS

My goal is to create a unique media player that can reload when a user wants to listen to an MP3 file. The concept is as follows: In media-player.js: - Display title, artist, and album art In programs.js: there is a button (LISTEN) that renders in medi ...

What are the circumstances under which JavaScript GCP libraries return null values?

My current project involves working with GCP and Firebase using typescript. I have been utilizing the provided libraries, specifically version 8 of Firebase, and have encountered some unexpected behavior. For instance (firebase, ver. 8.10.1) import 'f ...

Call a PHP function within a functions file using a JavaScript function

Seeking a way to navigate between PHP and JavaScript worlds with confidence. There's a collection of PHP functions stored neatly in custom_functions.php waiting to be called from JavaScript. As I delve into the realm of JavaScript and jQuery, my fam ...