Elasticsearch で特定の文字列を含むものでのソート方法を教えていただけませんでしょうか
// $search_input=検索文字 $query = [ 'query' => [ 'bool' => [ 'must' => [ ['match_phrase_prefix' => ['free_word' => ['query' => $search_input,'slop' => 1]]], ['term' => ['delete_flg' => 0]] ] ] ], 'from' => $from, 'size' => 20 ];
現在、上記のElasticsearch検索用クエリを使用し、
検索文字($search_input)を含むものを取得する処理を行っております。
そこで、以下のソート条件の実装を行いたいです。
第一ソート:検索文字を含むもの
第二ソート:「a,b,c」を含まないもの
Elasticsearchで上記ソート条件を実装する方法を知っている方がいらっしゃいましたら、
ご教授いただけませんでしょうか。
■一旦試したこと(第一ソート)
× :
cakephp
1 'sort' => [ 2 '_script' => [ 3 'type' => 'number', 4 'script' => [ 5 'lang' => 'painless', 6 'source' => ' 7 int priority = 0; 8 9 if (doc["eki_name"].value =~ /params.search_input/) { 10 priority += 2; 11 } 12 13 if (doc["syz_name"].value =~ /params.search_input/) { 14 priority += 2; 15 } 16 17 return priority; 18 ', 19 'params' => [ 20 'search_input' => $search_input 21 ] 22 ], 23 'order' => 'desc' 24 ], 25 '_score' 26 ],
※現在、実装方法を調べている途中です。
あなたの回答
tips
プレビュー