Elastic Search: How to write multi statement scripts?

后端 未结 2 552
再見小時候
再見小時候 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:26

    If you want to break your script into multiple lines you have to surrond your script with """ docs

    `"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;
              """
            }
          }
        }
      }
    }`
    

    Update: For some versions of Elasticsearch source should be replaced with inline docs

提交回复
热议问题