elasticsearch - 应该 + ElasticSearch 中的 distance_function
问题描述
我试图在 Elasticsearch 中返回的值中加权地理邻近性。我希望紧密接近不如某些字段(例如legal_name)重要,但比其他字段更重要。
从文档看来,目前的方法是使用distance_feature。但是,我创建的应该条件永远不会以任何相关方式改变结果。事实上,如果我取出 must 值,看起来分数是基于更远距离的。也就是说,更高的分数与更远的距离相关。当然,我想要的是近距离奖励分数。任何关于我可能做错了什么的建议表示赞赏......
(注意——“坐标”字段的类型为 geo_point)
简化文档
{
_index: "organizations",
_type: "_doc",
_id: "3",
_version: 9,
_seq_no: 16944,
_primary_term: 5,
found: true,
_source: {
id: 3,
legal_name: "Air Canada",
operating_name: "Air Canada",
...
coordinate: "43.85133,-79.36572",
}
}
询问
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [{
"multi_match": {
"query": "Air Canada",
"fields": ["legal_name^7","operating_name^7","interest_areas^4","city^3", "description","state","country"
]
}},
{"term" : { "organization_type.keyword": "Sponsor" }},
{"term" : { "approved" : true }}
],
"should": {
"distance_feature": {
"field": "coordinate",
"pivot": "25km",
"origin": [43.63, -79.3716],
"boost": 5.0
}
}
}
}
}```
解决方案
最后,我放弃了 distance_feature 并改用了高斯函数。
{“来自”:0,“大小”:20,“查询”:{
"function_score": {
"query": {
"bool": {
"must": [{
"multi_match": {
"query": "national bank",
"fields": ["legal_name^0.7", "operating_name^0.7", "interest_areas^0.4", "city^0.4", "description^0.4", "state^0.1", "country^0.1"]
}},
{"term" : { "organization_type.keyword": "Sponsor" }},
{"term" : { "approved" : true }}
]
}
},
"boost": "1",
"boost_mode": "sum",
"functions": [{
"gauss": {
"coordinate": {
"origin": { "lat": 43.63, "lon": -79.3716 },
"offset": "500km",
"decay": 0.5,
"scale": "100km"
}
},
"weight": 1
}]
}
} }`
推荐阅读
- typescript - 如何像这样修复 TypeScript 错误(ts:2740)
- c# - asp.net core 3.1 将 autofac 与 finbuckle 集成
- getstream-io - 当用户取消关注 GetStream 上的提要时,如何处理“关注”活动?
- reactjs - 反应如何在渲染功能后更新 DOM 组件
- javascript - 将 html5canvas 转换为图像后,它不会作为图像插入 html
- audio - Openvidu - 将视频通话音频设置为扬声器 Android
- css - 更改所选元素的样式
- unity3d - Skybox 不显示在 RenderTexture 上
- c# - 如何从后面的代码将文本对齐应用于 LoadingRow 事件上的数据网格行
- c++ - 如何在 C++ 中处理多个连接对象