Here's a simpler way to ask the question:

I've got this:

GeoDistanceSortBuilder sorter = new 
GeoDistanceSortBuilder("values.geo_location");
sorter.point(0.0, 0.0);
sorter.order(SortOrder.DESC);
sorter.unit(DistanceUnit.KILOMETERS);
sorter.geoDistance(GeoDistance.PLANE);
sorter.toString()


Which produces the string

"_geo_distance"{
   "values.geo_location" : [ 0.0, 0.0 ],
   "unit" : "km",
   "distance_type" : "plane",
   "reverse" : true
}


I would like to do the opposite.  I have the above string, and I want to 
turn it into a GeoDistanceSortBuilder without having to manually parse it.

On Monday, January 19, 2015 at 7:50:17 PM UTC-5, Alex Thurston wrote:
>
> I would like to turn an arbitrary JsonObject (which presumably follows the 
> Search/Sort DSL into a SortBuilder which can then be passed to the 
> SearchRequestBuilder::addSort.
>
> I've gotten this to work by simple parsing the JsonObject myself and 
> calling the appropriate calls in the SortBuilder, but that means that I 
> have to implement the parsing for every variation of the DSL.
>
> If I've got a Java JsonObject that looks like:
>
> {
>    "first_name": "asc"
> }
>
> OR
>
> {
>   "first_name": {
>     "order": "asc"
>   }
> }
>
> OR
>
> {
>   "_geo_distance":{
>     "my_position":{
>       "order": "asc"
>     }
>   }
> }
>
> All of which are valid Json for the sort, I would imagine there's a way to 
> call:
>
> JsonObject sort_json = <EXAMPLE FROM ABOVE>
> SortBuilder sort = new SortBuilder()
> sort.setSort(sort_json);
>
> I'm almost certain I'm missing something but can't for the life of me 
> figure out how to do it.
>
> Thanks in advance.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/a756b6b3-7e28-44f7-be88-e8d6e102b6e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to