title: Aggregation query fails using ElasticSearch Python client
body: <pre><code>Here is an aggregation query that works as expected when I use dev tools in on Elastic Search :  
  
     search_query = {
        &quot;aggs&quot;: {
          &quot;SHAID&quot;: {
            &quot;terms&quot;: {
              &quot;field&quot;: &quot;identiferid&quot;,
              &quot;order&quot;: {
                &quot;sort&quot;: &quot;desc&quot;
              },
      #         &quot;size&quot;: 100000
            },
            &quot;aggs&quot;: {
              &quot;update&quot;: {
                &quot;date_histogram&quot;: {
                  &quot;field&quot;: &quot;endTime&quot;,
                  &quot;calendar_interval&quot;: &quot;1d&quot;
                },
                &quot;aggs&quot;: {
                  &quot;update1&quot;: {
                        &quot;sum&quot;: {
                          &quot;script&quot;: {
                            &quot;lang&quot;: &quot;painless&quot;,
                            &quot;source&quot;:&quot;&quot;&quot;
                                if (doc['distanceIndex.att'].size()!=0) { 
                                    return doc['distanceIndex.att'].value;
                                } 
                                else { 
                                    if (doc['distanceIndex.att2'].size()!=0) { 
                                    return doc['distanceIndex.att2'].value;
                                }
                                return null;
                                }
                                &quot;&quot;&quot;
                          }
                        }
                      },
                  &quot;update2&quot;: {
                           &quot;sum&quot;: {
                          &quot;script&quot;: {
                            &quot;lang&quot;: &quot;painless&quot;,
                            &quot;source&quot;:&quot;&quot;&quot;
                                if (doc['distanceIndex.att3'].size()!=0) { 
                                    return doc['distanceIndex.att3'].value;
                                } 
                                else { 
                                    if (doc['distanceIndex.at4'].size()!=0) { 
                                    return doc['distanceIndex.att4'].value;
                                }
                                return null;
                                }
                                &quot;&quot;&quot;
                          }
                        }
                    },
                }
              },
              &quot;sort&quot;: {
                &quot;sum&quot;: {
                  &quot;field&quot;: &quot;time2&quot;
                }
              }
            }
          }
        },
      &quot;size&quot;: 0,
        &quot;query&quot;: {
          &quot;bool&quot;: {
            &quot;filter&quot;: [
              {
                &quot;match_all&quot;: {}
              },
              {
                &quot;range&quot;: {
                  &quot;endTime&quot;: {
                    &quot;gte&quot;: &quot;2021-11-01T00:00:00Z&quot;,
                    &quot;lt&quot;: &quot;2021-11-03T00:00:00Z&quot;
                  }
                }
              }
            ]
          }
        }
      }
  </code></pre>
  <p>When I attempt to execute this aggregation using the Python ElasticSearch client (<a href="https://elasticsearch-py.readthedocs.io/en/v7.15.1/" rel="nofollow noreferrer">https://elasticsearch-py.readthedocs.io/en/v7.15.1/</a>) I receive the exception :</p>
  <pre><code>exception search() got multiple values for keyword argument 'size'
  </code></pre>
  <p>If I remove the attribute :</p>
  <pre><code>&quot;size&quot;: 0,
  </code></pre>
  <p>From the query then the exception is not thrown but the aggregation does not run as <code>&quot;size&quot;: 0,</code> is required for an aggregation.</p>
  <p>Is there a different query format I should use for performing aggregations using the Python ElasticSearch client ?</p>
  <p>Update :</p>
  <p>Here is code used to invoke the query :</p>
  <pre><code>import elasticsearch
  from elasticsearch import Elasticsearch, helpers
  
  es_client = Elasticsearch(
      [&quot;https://test-elastic.com&quot;],
      scheme=&quot;https&quot;,
      port=443,
      http_auth=(&quot;test-user&quot;, &quot;test-password&quot;),
      maxsize=400,
      timeout=120,
      max_retries=10,
      retry_on_timeout=True
  )
  
  query_response = helpers.scan(client=es_client,
                                       query=search_query,
                                       index=&quot;test_index&quot;,
                                       clear_scroll=False,
                                       request_timeout=1500)
  
  rows = []
  try:
      for row in query_response:
          rows.append(row)
  except Exception as e:
      print('exception' , e)
          
  </code></pre>
  <p>Using <code>es_client</code> :</p>
  <pre><code>es_client.search(index=&quot;test_index&quot;, query=search_query)
  </code></pre>
  <p>results in error :</p>
  <pre><code>/opt/oss/conda3/lib/python3.7/site-packages/elasticsearch/connection/base.py in _raise_error(self, status_code, raw_data)
      336 
      337         raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
  --&gt; 338             status_code, error_message, additional_info
      339         )
      340 
  
  RequestError: RequestError(400, 'parsing_exception', 'unknown query [aggs]')
  </code></pre>
  <p>Is <code>aggs</code> valid for search api ?</p>