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)