# Add Script Field has stopped returning any hits data

**URL:** <https://discuss.elastic.co/t/add-script-field-has-stopped-returning-any-hits-data/78569>\
**Category:** Elasticsearch\
**Created:** [March 14, 2017, 5:37pm UTC](https://discuss.elastic.co/t/add-script-field-has-stopped-returning-any-hits-data/78569 "2017-03-14T17:37:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ciaran\_Potter](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Ciaran\_Potter](https://discuss.elastic.co/u/Ciaran_Potter)\
**Post date:** [March 14, 2017, 5:37pm UTC](https://discuss.elastic.co/t/add-script-field-has-stopped-returning-any-hits-data/78569/1 "2017-03-14T17:37:27Z")

</div>

Hi, I have a query that I am performing in java where I am trying to return the nearest events by location. I am also trying to return the distance in Miles for each result.  
Here is what i have so far, I have got this query working fine without the script field. But when I add the script field it shows me a non-zero value for hits and an empty InternalSearchHit class.

```
String[] includeSourceValues = new String[]{"location", "someKey1", "someKey2", "someKey3"};

		return connection.getClient().prepareSearch(index)
				.setSearchType(SearchType.QUERY_THEN_FETCH)
				.setQuery(aBoolQuery)
				.setFetchSource(includeSourceValues, null)
				.addScriptField("geoDistance", new Script("doc[\"location\"].distance(" + latitude + "," + longitude + ")"))
				.addSort(SortBuilders.geoDistanceSort("location", latitude, longitude))
				.setSize(limit)
				.get();

```

I am sorry if this is a repeat I have seen similar problems using the elastic search api, which I have tried to apply in java(and probably failed).

I also can't be certain that the script itself is working (I haven't seen any results since i included it)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 11, 2017, 5:37pm UTC](https://discuss.elastic.co/t/add-script-field-has-stopped-returning-any-hits-data/78569/2 "2017-04-11T17:37:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
