title: Named queries in Elasticsearch
body: <p>I need to search through a database with 3 keywords(3 queries), and I need to tell the user which of the keywords (query) that gave a result.
  I've been looking into Named Queries as a possible solution.</p>
  
  <p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html</a></p>
  
  <p>I was wondering if it is possible to apply named queries to a nested query?</p>
  
  <p>According to the documentation: </p>
  
  <blockquote>
    <p>The search response will include for each hit the matched_queries it
    matched on.</p>
  </blockquote>
  
  <p>So I tried with just one easy query to see how it works, I got a result, but no "matched_queries". Did I do something wrong?</p>
  
  <p>This is my query in Kibana: (Im not using actual name)</p>
  
  <pre><code>GET database/document/_search
  {
      "query": {
          "nested": {
              "path": "first_path",
              "query": {
                  "nested" : {
                      "path" :  "second_path",
                      "query" :  {
                         "match": {
                             "match_field": {
                             "query": "First query",
                             "_name" : "query"
                         }
                      }
                  } 
                 }
              },
              "inner_hits": {}
          }
      }
  }
  </code></pre>