Elastic Search: How to write multi statement scripts?

后端 未结 2 567
再見小時候
再見小時候 2021-01-12 01:47

I have values stored on a document in an Elasticsearch index.
I need to do some date manipulation on the values and return a boolean value to be used in a filter.
Th

2条回答
  •  甜味超标
    2021-01-12 02:41

    You simply need to separate each statement with a semicolon:

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

    Make sure to not add line breaks inside your script string, though, as it would not be valid JSON.

提交回复
热议问题