Elasksearch Java API Function Score Query with geo and time gauss

I am currently trying to build this function evaluation request using the elasticsearch Java API:

{ "query": { "function_score": { "functions": [ { "gauss": { "location": { "origin": { "lat": 52.55, "lon": 13.69 }, "offset": "30km", "scale": "10km", "decay": 0.9 } } }, { "gauss": { "createdAt": { "origin": "2015-06-14T15:50:00", "scale": "8h", "offset": "4h", "decay": 0.75 } } } ] } } } 

But I can not find any documentation regarding java api and function evaluation requests. This is what I have so far:

 elasticsearch.client .prepareSearch(config.offerIndex.value) .setQuery( QueryBuilders.functionScoreQuery( ScoreFunctionBuilders .gaussDecayFunction("location", ???, ???).setDecay(0.9) ) ) 

The second and third parameter of the gaussDecay function are called the initial and large-scale ones. But they have some type, and I have no idea how I should provide my location and time data. And the next question is how can I provide functions in FunctionScore Builder

+5
source share
1 answer

I found this solution, but I'm not sure if this is a clean way to do this. I would be grateful if someone could approve of it.

 val lat = 52.52 val lon = 13.402 QueryBuilders .functionScoreQuery( ScoreFunctionBuilders.gaussDecayFunction("location", new GeoPoint(lat, lon), "10km") .setDecay(0.9) .setOffset("30km")) .add( ScoreFunctionBuilders.gaussDecayFunction("createdAt", new DateTime(), "8h") .setDecay(0.75) .setOffset("4h")) ) 
+6
source

All Articles