title: How to write Elasticsearch multiple must scripts query?
body: <p>I want to use a query to compare multiple fields. I have field 1 to 4. I want to search data which field 1 is greater than field 2 and below query is work perfectly;</p>
  
  <pre><code>{
      "size": 0,
      "_source": [
          "field1",
          "field2",
          "field3",
          "field4"
      ],
      "sort": [],
      "query": {
          "bool": {
              "filter": [],
              "must": {
                  "script": {
                      "script": {
                          "inline": "doc['field1'].value &gt; doc['field2'].value;",
                          "lang": "painless"
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Now, I want to search data which field 1 is greater than field 2 and also which field 3 is greater than field 4. according <a href="https://stackoverflow.com/a/33480475/2671470">Elastic Search: How to write multi statement scripts?</a> and <a href="https://discuss.elastic.co/t/is-there-any-way-to-update-multiple-fields-by-update-by-query/70644/2" rel="nofollow noreferrer">This link</a> I just need to separate each statement with a semicolon. So it should be like this:</p>
  
  <pre><code>{
      "size": 0,
      "_source": [
          "field1",
          "field2",
          "field3",
          "field4"
      ],
      "sort": [],
      "query": {
          "bool": {
              "filter": [],
              "must": {
                  "script": {
                      "script": {
                          "inline": "doc['field1'].value &gt; doc['field2'].value; doc['field3'].value &gt; doc['field4'].value;",
                          "lang": "painless"
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>But that query doesn't work and return compile error like this:</p>
  
  <blockquote>
    <p>{"root_cause":[{"type":"script_exception","reason":"compile
    error","script_stack":["doc['field1'].value > doc[' ...","^----
    HERE"],"script":"doc['field1'].value > doc['field2'].value;
    doc['field1'].value > doc['field2'].value;
    ","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all
    shards
    failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"financials","node":"8SXaM2HcStelpLHvTDSMCQ","reason":{"type":"query_shard_exception","reason":"failed
    to create query: {\n \"bool\" : {\n \"must\" : [\n {\n \"script\" :
    {\n \"script\" : {\n \"source\" : \"doc['field1'].value >
    doc['field2'].value; doc['field1'].value > doc['field2'].value; \",\n
    \"lang\" : \"painless\"\n },\n \"boost\" : 1.0\n }\n }\n ],\n
    \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n
    }\n}","index_uuid":"hz12cHg1SkGwq712n6BUIA","index":"financials","caused_by":{"type":"script_exception","reason":"compile
    error","script_stack":["doc['field1'].value > doc[' ...","^----
    HERE"],"script":"doc['field1'].value > doc['field2'].value;
    doc['field1'].value > doc['field2'].value;
    ","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Not
    a statement."}}}}]}</p>
  </blockquote>