Elastic search: how to write scripts of several operators?

I have values ​​stored in a document in an Elasticsearch index.
I need to do some date manipulation for the values ​​and return the boolean value that will be used in the filter.
The script spans multiple lines, and I cannot get it to work.

I have written other single scripts that work just fine, however I know less than nothing about Groovy and very little about finding Elastic.

Each sample that I can find with the script has one line and only one line.

So basically, how would I take this perfectly valid script

"script": {
    "script": "doc['state'].value == 'completed' && doc['lastStateUpdate'].value < doc['dueDate'].value"
    }

And turn it into something like

"script": {
    "script": "def isCompleted = doc['state'].value == 'completed' 
               def preSLA = doc['lastStateUpdate'].value < doc['dueDate'].value
               return isCompleted && preSLA"
    }

, liner , , , , , " " isn .

. , , , , .

+4
2

:

"script": {
    "script": "isCompleted = doc['state'].value == 'completed'; preSLA = doc['lastStateUpdate'].value < doc['dueDate'].value; return isCompleted && preSLA;"
    }

script, JSON.

+10

, """

'"query": {
    "function_score": {
      "script_score": {
        "script": {
          "lang": "painless",
          "source": """
            int total = 0;
            for (int i = 0; i < doc['goals'].length; ++i) {
              total += doc['goals'][i];
            }
            return total;
          """
        }
      }
    }
  }
}'

: Elasticsearch source inline .

+5

Source: https://habr.com/ru/post/1614160/


All Articles