<p dir="auto">The matched_queries item in the response is missing when using a filtered query with nested filter that does not have a must_not clause.</p>
<p dir="auto">ES version 1.5.2</p>
<p dir="auto">Steps to reproduce:</p>
<p dir="auto">Create index and mapping</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT /test_index

PUT /test_index/doc_type/_mapping
{
  &quot;doc_type&quot;: {
    &quot;dynamic&quot;: &quot;strict&quot;,
    &quot;properties&quot;: {
      &quot;nestedDoc&quot;: {
        &quot;type&quot;: &quot;nested&quot;,
        &quot;dynamic&quot;: &quot;strict&quot;,
        &quot;properties&quot;: {
          &quot;field1&quot;: {
            &quot;type&quot;: &quot;string&quot;
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">PUT /test_index

PUT /test_index/doc_type/_mapping
{
  "doc_type": {
    "dynamic": "strict",
    "properties": {
      "nestedDoc": {
        "type": "nested",
        "dynamic": "strict",
        "properties": {
          "field1": {
            "type": "string"
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Add a document</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT /test_index/doc_type/1
{
  &quot;nestedDoc&quot;: [
    {
      &quot;field1&quot;: &quot;a&quot;
    },
    {
      &quot;field1&quot;: &quot;b&quot;
    }
  ]
}"><pre class="notranslate"><code class="notranslate">PUT /test_index/doc_type/1
{
  "nestedDoc": [
    {
      "field1": "a"
    },
    {
      "field1": "b"
    }
  ]
}
</code></pre></div>
<p dir="auto">Nested filter query with only a must clause</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="GET /test_index/doc_type/_search
{
  &quot;query&quot; : {
    &quot;filtered&quot; : {
      &quot;query&quot; : {
        &quot;match_all&quot; : { }
      },
      &quot;filter&quot; : {
        &quot;bool&quot; : {
          &quot;should&quot; : {
            &quot;bool&quot; : {
              &quot;must&quot; : {
                &quot;nested&quot; : {
                  &quot;filter&quot; : {
                    &quot;bool&quot; : {
                      &quot;must&quot; : {
                        &quot;term&quot; : {
                          &quot;field1&quot; : &quot;b&quot;
                        }
                      }
                    }
                  },
                  &quot;path&quot; : &quot;nestedDoc&quot;
                }
              },
              &quot;_name&quot; : &quot;QueryName&quot;
            }
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">GET /test_index/doc_type/_search
{
  "query" : {
    "filtered" : {
      "query" : {
        "match_all" : { }
      },
      "filter" : {
        "bool" : {
          "should" : {
            "bool" : {
              "must" : {
                "nested" : {
                  "filter" : {
                    "bool" : {
                      "must" : {
                        "term" : {
                          "field1" : "b"
                        }
                      }
                    }
                  },
                  "path" : "nestedDoc"
                }
              },
              "_name" : "QueryName"
            }
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Returns result - no matched_queries item as expected</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;took&quot;: 1,
   &quot;timed_out&quot;: false,
   &quot;_shards&quot;: {
      &quot;total&quot;: 5,
      &quot;successful&quot;: 5,
      &quot;failed&quot;: 0
   },
   &quot;hits&quot;: {
      &quot;total&quot;: 1,
      &quot;max_score&quot;: 1,
      &quot;hits&quot;: [
         {
            &quot;_index&quot;: &quot;test_index&quot;,
            &quot;_type&quot;: &quot;doc_type&quot;,
            &quot;_id&quot;: &quot;1&quot;,
            &quot;_score&quot;: 1,
            &quot;_source&quot;: {
               &quot;nestedDoc&quot;: [
                  {
                     &quot;field1&quot;: &quot;a&quot;
                  },
                  {
                     &quot;field1&quot;: &quot;b&quot;
                  }
               ]
            }
         }
      ]
   }
}"><pre class="notranslate"><code class="notranslate">{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc_type",
            "_id": "1",
            "_score": 1,
            "_source": {
               "nestedDoc": [
                  {
                     "field1": "a"
                  },
                  {
                     "field1": "b"
                  }
               ]
            }
         }
      ]
   }
}
</code></pre></div>
<p dir="auto">Nested filter query with an additional must_not clause that does nothing</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="GET /test_index/doc_type/_search
{
  &quot;query&quot; : {
    &quot;filtered&quot; : {
      &quot;query&quot; : {
        &quot;match_all&quot; : { }
      },
      &quot;filter&quot; : {
        &quot;bool&quot; : {
          &quot;should&quot; : {
            &quot;bool&quot; : {
              &quot;must&quot; : {
                &quot;nested&quot; : {
                  &quot;filter&quot; : {
                    &quot;bool&quot; : {
                      &quot;must&quot; : {
                        &quot;term&quot; : {
                          &quot;field1&quot; : &quot;b&quot;
                        }
                      }
                    }
                  },
                  &quot;path&quot; : &quot;nestedDoc&quot;
                }
              },
              &quot;must_not&quot; : {
                &quot;exists&quot; : { &quot;field&quot; : &quot;_does_not_exist_&quot; }
              },
              &quot;_name&quot; : &quot;QueryName&quot;
            }
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">GET /test_index/doc_type/_search
{
  "query" : {
    "filtered" : {
      "query" : {
        "match_all" : { }
      },
      "filter" : {
        "bool" : {
          "should" : {
            "bool" : {
              "must" : {
                "nested" : {
                  "filter" : {
                    "bool" : {
                      "must" : {
                        "term" : {
                          "field1" : "b"
                        }
                      }
                    }
                  },
                  "path" : "nestedDoc"
                }
              },
              "must_not" : {
                "exists" : { "field" : "_does_not_exist_" }
              },
              "_name" : "QueryName"
            }
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Returns result with expected matched_queries item</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;took&quot;: 1,
   &quot;timed_out&quot;: false,
   &quot;_shards&quot;: {
      &quot;total&quot;: 5,
      &quot;successful&quot;: 5,
      &quot;failed&quot;: 0
   },
   &quot;hits&quot;: {
      &quot;total&quot;: 1,
      &quot;max_score&quot;: 1,
      &quot;hits&quot;: [
         {
            &quot;_index&quot;: &quot;test_index&quot;,
            &quot;_type&quot;: &quot;doc_type&quot;,
            &quot;_id&quot;: &quot;1&quot;,
            &quot;_score&quot;: 1,
            &quot;_source&quot;: {
               &quot;nestedDoc&quot;: [
                  {
                     &quot;field1&quot;: &quot;a&quot;
                  },
                  {
                     &quot;field1&quot;: &quot;b&quot;
                  }
               ]
            },
            &quot;matched_queries&quot;: [
               &quot;QueryName&quot;
            ]
         }
      ]
   }
}"><pre class="notranslate"><code class="notranslate">{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc_type",
            "_id": "1",
            "_score": 1,
            "_source": {
               "nestedDoc": [
                  {
                     "field1": "a"
                  },
                  {
                     "field1": "b"
                  }
               ]
            },
            "matched_queries": [
               "QueryName"
            ]
         }
      ]
   }
}
</code></pre></div>
<p dir="auto">Thanks for your response however:</p>
<p dir="auto">As stated there are only two shards per node (one of them even a replica of <em>another</em> index) and still I get 3(!!!) slowquery logs.</p>
<p dir="auto">Would there be any other possible reason?</p>
<p dir="auto">Elasticsearch version: 2.3.4</p>
<p dir="auto">JVM version: 1.7.0_101</p>
<p dir="auto">OS version: Ubuntu 14.04</p>
<p dir="auto">Description of the problem including expected versus actual behavior:</p>
<p dir="auto">Our setup is as follows:<br>
An index over 11 nodes each of them holding 2 shards one primary and one replica (not of the same shard).<br>
When running a slow query of search_type QUERY_THEN_FETCH and looking at the elasticsearch slow query logs we see that on each of the nodes we are getting 3 calls of the exact same query with timestamps miliseconds apart.<br>
We were wondering whether this is a "feature" of the slow query logging or whether there are really 3 distinct calls of the same query performed on the index and if the latter, what would be an explanation for this.</p>
<p dir="auto">The query we are running is:<br>
{"index":["index-****************_"],"search_type":"count","ignore_unavailable":true}<br>
{"size":0,"aggs":{"2":{"date_histogram":{"field":"<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timestamp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timestamp">@timestamp</a>","interval":"30m","time_zone":"+03:00","min_doc_count":1,"extended_bounds":{"min":1469318400000,"max":1469393384478}},"aggs":{"3":{"terms":{"field":"level","size":5,"order":{"<em>count":"desc"}}}}}},"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":""}},"filter":{"bool":{"must":[{"query":{"match":{"type":{"query":"mainlog","type":"phrase"}}}},{"range":{"<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timestamp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timestamp">@timestamp</a>":{"gte":1469318400000,"lte":1469393384478}}}],"must_not":[]}}}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"</em>":{}},"fragment_size":2147483647}}</p>
<p dir="auto">And the slow query log (after some processing on our end) is:<br>
[2016-07-28 07:53:00,561][INFO ][index.search.slowlog.query] [index-****************_]took[5.2s], took_millis[5209], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[11], source[{"size":0,"aggs":{"2":{"date_histogram":{"field":"<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timestamp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timestamp">@timestamp</a>","interval":"30m","time_zone":"+03:00","min_doc_count":1,"extended_bounds":{"min":1469318400000,"max":1469393384478}},"aggs":{"3":{"terms":{"field":"level","size":5,"order":{"<em>count":"desc"}}}}}},"query":{"filtered":{"query":{"query_string":{"analyze_wildcard":true,"query":""}},"filter":{"bool":{"must":[{"query":{"match":{"type":{"query":"mainlog","type":"phrase"}}}},{"range":{"<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/timestamp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/timestamp">@timestamp</a>":{"gte":1469318400000,"lte":1469393384478}}}],"must_not":[]}}}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"</em>":{}},"fragment_size":2147483647}}], extra_source[],</p>
<p dir="auto">(the other two instances are exactly the same with a slight variance on the time taken)</p>