gpt4 book ai didi

symfony - elasticsearch距离排序和计算不正确和不准确

转载 作者:行者123 更新时间:2023-12-02 22:39:55 24 4
gpt4 key购买 nike

我正在使用Elasticsearch网站上的搜索功能。搜索必须提供距某个位置(例如25公里半径)的距离的搜索。

没问题,我正在使用以下Elasticsearch查询数组:

编辑3 :使用function_score更新查询

{
"index": "kasd9i9021profiles",
"type": "profile",
"size": 30,
"from": 0,
"body": {
"query": {
"function_score": {
"functions": [
{
"linear": {
"location": {
"origin": "49.449919468911,11.073560787681",
"offset": "2km",
"scale": "1km"
}
}
}
],
"score_mode": "avg",
"boost_mode": "replace",
"query": {
"bool": {
"must": [
{
"term": {
"published": "1"
}
},
{
"match": {
"country": "DE"
}
}
],
"filter": {
"geo_distance": {
"distance": "25km",
"distance_type": "arc",
"_cache": true,
"location": {
"lat": 49.449919468911,
"lon": 11.073560787681
},
"unit": "km"
}
}
}
}
}
},
"aggs": {
"rings": {
"geo_distance": {
"field": "location",
"origin": "49.449919468911,11.073560787681",
"distance_type": "arc",
"unit": "km",
"ranges": [
{
"to": 25
}
]
}
}
},
"script_fields": {
"distance": {
"lang": "groovy",
"params": {
"lat": 49.449919468911,
"lon": 11.073560787681
},
"script": "doc['location'].distanceInKm(lat,lon)"
}
},
"sort": [
{
"upgrade_sort": {
"order": "desc"
}
},
{
"has_siegel": {
"order": "desc"
}
},
{
"_geo_distance": {
"location": {
"lat": 49.449919468911,
"lon": 11.073560787681
},
"order": "desc",
"unit": "km"
}
}
]
},
"fields": [
"_source",
"distance"
]
}

“upgrade_sort”的值可以在0到3之间。
“has_siegel”的值可以为true或false。

问题是:
  • 结果未按距离排序
  • 结果中的距离在0到30 km之间,而不是在0到25 km之间。

  • 那是错误还是错误的查询?

    编辑1

    对应:
    $params = [
    'index' => $name,
    'body' => [
    'mappings' => [
    'profile' => [
    'properties' => [
    'name' => [
    'type' => 'string',
    ],
    'logo_url' => [
    'type' => 'string',
    ],
    'foto_url' => [
    'type' => 'string',
    ],
    'info_text' => [
    'type' => 'string',
    ],
    'cPerson' => [
    'type' => 'string',
    ],
    'street' => [
    'type' => 'string',
    ],
    'city' => [
    'type' => 'string',
    ],
    'country' => [
    'type' => 'string',
    ],
    'website' => [
    'type' => 'string',
    ],
    'location' => [
    'type' => 'geo_point'
    ],
    'upgrade_sort' => [
    'type' => 'integer'
    ],
    ]
    ]
    ]
    ]
    ];

    结果:出于隐私原因,我无法发布完整结果。以下是距离的详细信息:

    编辑2

    坐标加法器
    distance: 9,82km
    has_siegel: 0
    upgrade_sort: 3
    lon: 10.988270100000022
    lat: 49.4724229

    distance: 10,87km
    has_siegel: 0
    upgrade_sort: 2
    lon: 10.980907500000058
    lat: 49.4808363

    distance: 15,71km
    has_siegel: 0
    upgrade_sort: 1
    lon: 11.017770000000041
    lat: 49.5795

    distance: 0,15km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.072768300000007
    lat: 49.4488594

    distance: 0,32km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.07072740000001
    lat: 49.44968069999999

    distance: 0,32km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.07072740000001
    lat: 49.44968069999999

    distance: 0,47km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.077651400000036
    lat: 49.4487752

    distance: 0,60km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.078965499999981
    lat: 49.4501188

    distance: 0,61km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.078960000000052
    lat: 49.45074

    distance: 0,56km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.076950099999976
    lat: 49.4536002

    distance: 0,83km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.080846599999973
    lat: 49.4483038

    distance: 0,70km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.07790239999997
    lat: 49.45442389999999

    distance: 0,70km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.07790239999997
    lat: 49.45442389999999

    distance: 0,94km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.065464399999996
    lat: 49.4475953

    distance: 0,72km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.075771300000042
    lat: 49.4560251

    distance: 1,14km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.066973200000007
    lat: 49.4578074

    distance: 1,40km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.084297399999969
    lat: 49.4563874

    distance: 1,23km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.077985799999965
    lat: 49.4397852

    distance: 1,41km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.081709400000022
    lat: 49.440276

    distance: 1,51km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.067300100000011
    lat: 49.4619894

    distance: 2,48km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.092409999999973
    lat: 49.4618

    distance: 3,65km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.104663200000005
    lat: 49.4602779

    distance: 3,74km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.100480000000061
    lat: 49.47002

    distance: 4,12km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.043360000000007
    lat: 49.42859

    distance: 4,16km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.100729999999999
    lat: 49.47564

    distance: 5,61km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.032510600000023
    lat: 49.4207607

    distance: 5,41km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.093795699999987
    lat: 49.4057095

    distance: 6,60km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.033873800000038
    lat: 49.4058283

    distance: 7,51km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.016179100000045
    lat: 49.4143705

    distance: 7,49km
    has_siegel: 0
    upgrade_sort: 0
    lon: 11.130335599999967
    lat: 49.41382410000001

    最佳答案

    您的过滤器仅排除半径25公里范围内的结果。如果要按距离对结果进行排序,则必须使用function score query with a decay function

    对于距离,如文档中所述,如果要使其更准确,则应使用the arc distance_type

    关于symfony - elasticsearch距离排序和计算不正确和不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34372194/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com