ElasticSearch - 按分数和位置排序

I use elasticsearch. I need to find the results by word and sort them by deception (_score), and then by distance (_geo_distance) By coincidence of phrases, I find the following sensations and sort them out by coincidence (_score).

Array
(
    [took] => 23
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 469
            [max_score] => 5.350864
            [hits] => Array
                (
                    [0] => Array
                        (
                            [_index] => salon
                            [_type] => services
                            [_id] => 7686
                            [_score] => 5.350864
                            [_source] => Array
                                (
                                    [service_name] => Found a string 1
                                    [service_id] => 10493
                                    [location] => Array
                                        (
                                            [lat] => 55.701328
                                            [lon] => 37.507412
                                        )

                                )

                        )

                    [1] => Array
                        (
                            [_index] => salon
                            [_type] => services
                            [_id] => 8350
                            [_score] => 5.350864
                            [_source] => Array
                                (
                                    [service_name] => Found a string 2
                                    [service_id] => 11171
                                    [location] => Array
                                        (
                                            [lat] => 55.869915
                                            [lon] => 37.613728
                                        )

                                )

                        )

                    [2] => Array
                        (
                            [_index] => salon
                            [_type] => services
                            [_id] => 14883
                            [_score] => 5.237593
                            [_source] => Array
                                (
                                    [service_name] => Found a string 3
                                    [service_id] => 17851
                                    [location] => Array
                                        (
                                            [lat] => 55.691734
                                            [lon] => 37.728164
                                        )

                                )

                        )

...

But I do not understand how to add more and sorting by coordinates, for example, so that would be sorted by the nearest to 55.69,37.72

Here is my search code in elasticsearch:

require 'vendor/autoload.php';
function searchES($word) {

    $client = \Elasticsearch\ClientBuilder::create()->setHosts([ES_HOST])->build();

    $IDs = [];
    $params = [];
    $params['index'] = ES_INDEX;

    if ($client->indices()->exists($params)) {

        $params['type'] = ES_TYPE;
        $params['size'] = 10000;
        $params['body']['sort'] = ['_score' => 'desc'];
        $params['body']['query']['match']['service_name'] = trim($word);


        $result = $client->search($params);

        if ($result['hits']['total'] > 0) {

            $result = $result['hits']['hits'];

            foreach ($result as $val) {

                $k = $val['_source']['service_id'];
                $IDs[$k] = $val['_source']['service_name'];

            }

        }

    }

    return $IDs;
}

Params:

Array
(
    [index] => salon
    [body] => Array
        (
            [settings] => Array
                (
                    [analysis] => Array
                        (
                            [filter] => Array
                                (
                                    [ru_stop] => Array
                                        (
                                            [type] => stop
                                            [stopwords] => _russian_
                                        )

                                    [ru_stemmer] => Array
                                        (
                                            [type] => stemmer
                                            [language] => russian
                                        )

                                )

                            [analyzer] => Array
                                (
                                    [default] => Array
                                        (
                                            [tokenizer] => standard
                                            [filter] => Array
                                                (
                                                    [0] => lowercase
                                                    [1] => ru_stop
                                                    [2] => ru_stemmer
                                                )

                                        )

                                )

                        )

                )

            [mappings] => Array
                (
                    [_default_] => Array
                        (
                            [properties] => Array
                                (
                                    [service_name] => Array
                                        (
                                            [type] => string
                                            [analyzer] => default
                                        )

                                )

                        )

                )

        )

)
douye2111
douye2111 可能重复的Java-Elasticsearch:基于距离排序
3 年多之前 回复
douxiong0668
douxiong0668 是的,在问题的文本中添加
3 年多之前 回复
dou7466
dou7466 你能告诉我们这个映射吗?
3 年多之前 回复
dongzj2015
dongzj2015 不,我不明白如何正确设置位置的排序条件
3 年多之前 回复
dotcraq3249
dotcraq3249 您是否收到此消息“如果不使用特定的排序功能,如geo_distance,则无法对geo_point字段进行排序”?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问