title: Spring data elasticsearch: setting sort value to entity field
body: <p>Finding nearest stores from elasticsearch, using geo distance sort using spring-data-elastic search.</p>
  <p><strong>Problem</strong></p>
  <p>StoreES getting populated with <em><strong>orgCode</strong></em> and <em><strong>storeCode</strong></em> , because they are in _source.
  How can I populate <em><strong>distance</strong></em> value from search response <em><strong>sort[0]</strong></em> value.</p>
  <blockquote>
  <p><strong>StoreElasticSearchRepository method</strong></p>
  </blockquote>
  <pre><code>public default List&lt;StoreES&gt; nearStores(Double latitude, Double longitude, Integer page, Integer size) {
      GeoDistanceSortBuilder distanceSortbuilder = SortBuilders.geoDistanceSort(&quot;location&quot;).point(latitude, longitude)
                          .order(SortOrder.ASC).unit(DistanceUnit.KILOMETERS);
                  SearchQuery query = new NativeSearchQueryBuilder().withQuery(QueryBuilders.matchAllQuery())
                          .withSort(distanceSortbuilder).withPageable(new PageRequest(page, size)).build();
                  FacetedPage&lt;StoreES&gt; storesPage = this.search(query);
      return storesPage.getContent();
  }
  </code></pre>
  <blockquote>
  <p><strong>Rest request equivalent for above query:</strong></p>
  </blockquote>
  <pre><code>{
    &quot;sort&quot;: {
      &quot;_geo_distance&quot;: {
        &quot;location&quot;: {
          &quot;lat&quot;: 12.9259,
          &quot;lon&quot;: 77.6229
        },
        &quot;order&quot;: &quot;asc&quot;,
        &quot;unit&quot;: &quot;km&quot;
      }
    }
  }
  </code></pre>
  <blockquote>
  <p><strong>Result for query</strong></p>
  </blockquote>
  <pre><code>    {
    &quot;took&quot;: 5,
    &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;: 1365,
      &quot;max_score&quot;: null,
      &quot;hits&quot;: [
        {
          &quot;_index&quot;: &quot;app&quot;,
          &quot;_type&quot;: &quot;store&quot;,
          &quot;_id&quot;: &quot;99991258&quot;,
          &quot;_score&quot;: null,
          &quot;_source&quot;: {
            &quot;id&quot;: 1,
            &quot;orgCode&quot;: &quot;ABC&quot;,
            &quot;storeCode&quot;: &quot;12345&quot;,
         },
        &quot;sort&quot;: [
            0.49933591591981075
          ]
  }
  </code></pre>
  <blockquote>
  <p><strong>Entity object</strong></p>
  </blockquote>
  <pre><code>public class StoreES{
  
      private String orgCode;
  
      private String storeCode;
    
      private Double distance;
  
  // setter gettter methods
  }
  </code></pre>
  <p>Thanks In advance.</p>