0

I am trying to create a function_score elasticsearch query using NEST (gauss function), and have a geo point object to pass as the 'origin', however the "Origin" method in NEST accepts only a string, a result elasticsearch can't parse the query. How can I write the query in NEST so Elasticsearch can parse it correctly?

var originLoc = JsonConvert.SerializeObject(userLocation.GeoCenter);
var searchDesc = new SearchDescriptor<MyCustomType>().Query(q => q.FunctionScore(fs => fs.Functions(func => func.Gauss("geoCenter", gs => gs.Origin(originLoc).Offset("1km").Scale("500m").Decay(0.99)))));

NEST passes the code above to elasticsearch like this, which elasticsearch can't parse (origin is parsed as string).

"query": {
"function_score": {
  "functions": [
    {
      "gauss": {
        "geoCenter": {
          "origin": "{\"lat\":29.745703,\"lon\":-95.740514}", //<-- string
          "scale": "500m",
          "offset": "1km",
          "decay": 0.99
        }
      }
    }
  ]
}

}

Below is the correct query that Elasticsearch can run (origin is parsed as geo point object)

"query": {
"function_score": {
  "functions": [
    {
      "gauss": {
        "geoCenter": {
          "origin": {  //<----- geo point serialized object
            "lon": -95.740514,
            "lat": 29.745703
          },
          "scale": "500m",
          "offset": "1km",
          "decay": 0.99
        }
      }
    }
  ]
}
Socardo
  • 520
  • 6
  • 14

1 Answers1

3

i have something like this in my code

.Query(f => f
        .FunctionScore(fs => fs
                        .BoostMode(FunctionBoostMode.Sum)
                        .Functions(ff => ff
                            .Linear("location", d => d.Origin(origin).Scale("8km").Decay(0.33))
                        )
        )
)

Where origin -> var origin = object.latitude + "," + object.longitude;

danvasiloiu
  • 751
  • 7
  • 24