title: Accessing nested elasticsearch fields in java
body: <p>So far I followed <a href="http://www.spacevatican.org/2012/5/12/elasticsearch-native-scripts-for-dummies/" rel="nofollow">this guide</a> to get native java scripts working with elasticsearch. Accessing normal non-nested fields works fine using <code>doc().field("fieldname")</code>.</p>
  
  <p>Does the same work for nested fields? How can I loop over them and access nested fields?</p>
  
  <p><strong>EDIT:</strong> After reading imotov's answer below I ended up including the nested field in the root document using <code>include_in_root</code> or <code>include_in_parent</code> (See <a href="http://www.elasticsearch.org/guide/reference/mapping/nested-type/" rel="nofollow">docs</a>).</p>
  
  <pre><code>GeoPoint[] locations = ((GeoPointDocFieldData)doc().field("places.location")).getValues();
  
  for (GeoPoint location : locations) {
      // Do Stuff
      double lat = location.lat();
      double lon = location.lon();
  }
  </code></pre>