title: Elasticsearch nested and aggregation query with python
body: <p>I'm relatively new to elasticsearch so pardon if it seems like a stupid question...
  I'm trying to query my elastic to find all the documents that contain a word (tag) inside a nested json that holds array of objects..</p>
  
  <p>example: 
  {
  ...
  "notes":  {
      ...
      "tags": {
          [{"n":100, "t": "data science"}, {"n":101, "t": "web development"}, {"n": 102, "t": "python"} ....]
      }
  }
  And I want to extract all the docuemnts (jsons) that have inside their tags one tag of data_science and one tag of python.</p>
  
  <p>I'm using the regular elasticsearch libraby for this (on python)
  and I've tried to use the aggs and nested docs but couldn't figure out 
  how to combine them and get the query I need.
  <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html</a>
  <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html</a></p>
  
  <pre><code>from elasticsearch import Elasticsearch
  
  es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
  
  body = '''
  {
      "query": {
          "nested" : {
              "path" : "my_index",
              "query" : {
                  "bool" : {
                      "must" : [
                      { "range" : {"my_index.notes.tags.t" : {"python": 2}} },
                      { "range" : {"my_index.notes.tags.t" : {"data science": 2}} }
                      ]
                  }
              },
              "score_mode" : "avg"
          }
      }
  }
  '''
  
  es.search(index="my_index", body=body)
  </code></pre>