php - ElasticSearch - order by score and location -
i use elasticsearch. need find results word , sort them deception (_score), , distance (_geo_distance) coincidence of phrases, find following sensations , sort them out 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 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 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 string 3 [service_id] => 17851 [location] => array ( [lat] => 55.691734 [lon] => 37.728164 ) ) ) ... but not understand how add more , sorting coordinates, example, sorted nearest 55.69,37.72
here 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 $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 ) ) ) ) ) )
Comments
Post a Comment