如何将对象传递给 NEST(FunctionScore 查询)中的 "Origin" 方法?
How to pass an object to "Origin" method in NEST (FunctionScore query)?
我正在尝试使用 NEST(高斯函数)创建一个 function_score elasticsearch 查询,并有一个地理点对象作为 'origin' 传递,但是 [= NEST中的24=]方法只接受一个字符串,结果elasticsearch无法解析query。
如何在 NEST 中编写查询以便 Elasticsearch 可以正确解析它?
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将上面的代码这样传递给elasticsearch,elasticsearch无法解析(origin解析为字符串)
"query": {
"function_score": {
"functions": [
{
"gauss": {
"geoCenter": {
"origin": "{\"lat\":29.745703,\"lon\":-95.740514}", //<-- string
"scale": "500m",
"offset": "1km",
"decay": 0.99
}
}
}
]
}
}
下面是 Elasticsearch 可以 运行 的正确查询(原点被解析为地理点对象)
"query": {
"function_score": {
"functions": [
{
"gauss": {
"geoCenter": {
"origin": { //<----- geo point serialized object
"lon": -95.740514,
"lat": 29.745703
},
"scale": "500m",
"offset": "1km",
"decay": 0.99
}
}
}
]
}
我的代码中有这样的东西
.Query(f => f
.FunctionScore(fs => fs
.BoostMode(FunctionBoostMode.Sum)
.Functions(ff => ff
.Linear("location", d => d.Origin(origin).Scale("8km").Decay(0.33))
)
)
)
哪里起源 -> var origin = object.latitude + "," + object.longitude;
我正在尝试使用 NEST(高斯函数)创建一个 function_score elasticsearch 查询,并有一个地理点对象作为 'origin' 传递,但是 [= NEST中的24=]方法只接受一个字符串,结果elasticsearch无法解析query。 如何在 NEST 中编写查询以便 Elasticsearch 可以正确解析它?
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将上面的代码这样传递给elasticsearch,elasticsearch无法解析(origin解析为字符串)
"query": {
"function_score": {
"functions": [
{
"gauss": {
"geoCenter": {
"origin": "{\"lat\":29.745703,\"lon\":-95.740514}", //<-- string
"scale": "500m",
"offset": "1km",
"decay": 0.99
}
}
}
]
}
}
下面是 Elasticsearch 可以 运行 的正确查询(原点被解析为地理点对象)
"query": {
"function_score": {
"functions": [
{
"gauss": {
"geoCenter": {
"origin": { //<----- geo point serialized object
"lon": -95.740514,
"lat": 29.745703
},
"scale": "500m",
"offset": "1km",
"decay": 0.99
}
}
}
]
}
我的代码中有这样的东西
.Query(f => f
.FunctionScore(fs => fs
.BoostMode(FunctionBoostMode.Sum)
.Functions(ff => ff
.Linear("location", d => d.Origin(origin).Scale("8km").Decay(0.33))
)
)
)
哪里起源 -> var origin = object.latitude + "," + object.longitude;