title: Elasticsearch - How to query nested fields?
body: <p>I created an ES index with the command below:</p>
  <pre><code>curl -XPUT -H &quot;Content-Type: application/json&quot; http://localhost:9200/nested_test?pretty=true -d '{&quot;mappings&quot;: {&quot;properties&quot;: {&quot;name&quot;: {&quot;type&quot;: &quot;keyword&quot;}, &quot;related&quot;: {&quot;type&quot;: &quot;nested&quot;, &quot;properties&quot;: {&quot;name&quot;: {&quot;type&quot;: &quot;keyword&quot;}, &quot;count&quot;: {&quot;type&quot;: &quot;long&quot;}}}}}}'
  </code></pre>
  <p>Which gave me the response:</p>
  <pre><code>{
    &quot;acknowledged&quot; : true,
    &quot;shards_acknowledged&quot; : true,
    &quot;index&quot; : &quot;nested_test&quot;
  }
  </code></pre>
  <p>Then I put some sample data in it:</p>
  <pre><code>curl -XPUT -H &quot;Content-Type: application/json&quot; http://localhost:9200/nested_test/_doc/1?pretty=true -d '{&quot;name&quot;: &quot;php&quot;, &quot;related&quot;: [{&quot;name&quot;: &quot;c#&quot;, &quot;count&quot;: 6806}, {&quot;name&quot;: &quot;c&quot;, &quot;count&quot;: 4080}, {&quot;name&quot;: &quot;java&quot;, &quot;count&quot;: 9745}, {&quot;name&quot;: &quot;javascript&quot;, &quot;count&quot;: 9141}]}'
  </code></pre>
  <p>Which gave me the response:</p>
  <pre><code>{
    &quot;_index&quot; : &quot;nested_test&quot;,
    &quot;_type&quot; : &quot;_doc&quot;,
    &quot;_id&quot; : &quot;1&quot;,
    &quot;_version&quot; : 1,
    &quot;result&quot; : &quot;created&quot;,
    &quot;_shards&quot; : {
      &quot;total&quot; : 2,
      &quot;successful&quot; : 1,
      &quot;failed&quot; : 0
    },
    &quot;_seq_no&quot; : 0,
    &quot;_primary_term&quot; : 1
  }
  </code></pre>
  <p>And then I finally tried to query it using the following command:</p>
  <pre><code>curl -X GET http://localhost:9200/nested_test/_search?pretty=true -H 'Content-Type: application/json' -d '{&quot;query&quot;: {&quot;nested&quot;: {&quot;path&quot;: &quot;related&quot;, &quot;query&quot;: {&quot;match&quot;: {&quot;related.name&quot;: &quot;javascript&quot;}}}}}'
  </code></pre>
  <p>And it gave me the following response:</p>
  <pre><code>{
    &quot;took&quot; : 1,
    &quot;timed_out&quot; : false,
    &quot;_shards&quot; : {
      &quot;total&quot; : 1,
      &quot;successful&quot; : 1,
      &quot;skipped&quot; : 0,
      &quot;failed&quot; : 0
    },
    &quot;hits&quot; : {
      &quot;total&quot; : {
        &quot;value&quot; : 1,
        &quot;relation&quot; : &quot;eq&quot;
      },
      &quot;max_score&quot; : 1.2039728,
      &quot;hits&quot; : [
        {
          &quot;_index&quot; : &quot;nested_test&quot;,
          &quot;_type&quot; : &quot;_doc&quot;,
          &quot;_id&quot; : &quot;1&quot;,
          &quot;_score&quot; : 1.2039728,
          &quot;_source&quot; : {
            &quot;name&quot; : &quot;php&quot;,
            &quot;related&quot; : [
              {
                &quot;name&quot; : &quot;c#&quot;,
                &quot;count&quot; : 6806
              },
              {
                &quot;name&quot; : &quot;c&quot;,
                &quot;count&quot; : 4080
              },
              {
                &quot;name&quot; : &quot;java&quot;,
                &quot;count&quot; : 9745
              },
              {
                &quot;name&quot; : &quot;javascript&quot;,
                &quot;count&quot; : 9141
              }
            ]
          }
        }
      ]
    }
  }
  </code></pre>
  <p>When I was expecting the following output:</p>
  <pre><code>{
    &quot;took&quot; : 1,
    &quot;timed_out&quot; : false,
    &quot;_shards&quot; : {
      &quot;total&quot; : 1,
      &quot;successful&quot; : 1,
      &quot;skipped&quot; : 0,
      &quot;failed&quot; : 0
    },
    &quot;hits&quot; : {
      &quot;total&quot; : {
        &quot;value&quot; : 1,
        &quot;relation&quot; : &quot;eq&quot;
      },
      &quot;max_score&quot; : 1.2039728,
      &quot;hits&quot; : [
        {
          &quot;_index&quot; : &quot;nested_test&quot;,
          &quot;_type&quot; : &quot;_doc&quot;,
          &quot;_id&quot; : &quot;1&quot;,
          &quot;_score&quot; : 1.2039728,
          &quot;_source&quot; : {
            &quot;name&quot; : &quot;php&quot;,
            &quot;related&quot; : [
              {
                &quot;name&quot; : &quot;javascript&quot;,
                &quot;count&quot; : 9141
              }
            ]
          }
        }
      ]
    }
  }
  </code></pre>
  <p>Can anyone point out what it is that I am doing wrong?</p>