2017-02-11 19 views
0

私はちょうどエラスティックサーチを通して自分のやり方をしており、オートコンプリート機能に関する助けが必要です。エラスティックサーチ2次検索オーダーでオートコンプリート

基本的に私はオートコンプリート機能を使用していますが、私の母集団フィールドの降順を使用してセカンダリソート順を追加します。しかし、私はクエリにソートパラメータを挿入すると、それは私に400エラーメッセージを与えます。私のマッピングとクエリを見て、それらが正しく設定されているかどうかを確認し、この作業を行うために必要なことを提案できますか?

多くのありがとうございます。

マッピング:

PUT /ff_search_locations2?pretty 
{ 
    "mappings": { 
    "1": { 
     "_all": { 
     "enabled": false 
     }, 
     "properties": { 
     "city": { 
      "type": "text" 
     }, 
     "county": { 
      "type": "text" 
     }, 
     "region": { 
      "type": "text" 
     }, 
     "country": { 
      "type": "text" 
     }, 
     "url": { 
      "type": "text" 
     }, 
     "combined": { 
      "type": "completion" 
     }, 
     "city_lc": { 
      "type": "text" 
     }, 
     "population": { 
      "type": "text" 
     }, 
     "location": { 
      "type": "geo_point" 
     } 
     } 
    } 
    } 
} 

私の作業クエリ:

POST /ff_search_locations2/_suggest?pretty&pretty 
{ 
    "1": { 
    "prefix": "london", 
    "completion": { 
     "field": "combined" 
    } 
    } 
} 

私が試したもの:

POST /ff_search_locations2/_suggest?pretty&pretty 
{ 
    "1": { 
    "prefix": "london", 
    "completion": { 
     "field": "combined" 
    } 

    }, 
    "sort": { "population": { "order": "desc" }} 
} 

と返されたエラー:

{ 
    "error": { 
    "root_cause": [ 
     { 
     "type": "illegal_argument_exception", 
     "reason": "suggester with name [population] not supported" 
     } 
    ], 
    "type": "illegal_argument_exception", 
    "reason": "suggester with name [population] not supported" 
    }, 
    "status": 400 
} 

私は、インデックスを生成するために使用しているPHPコード:

error_reporting(-1); 
ini_set('display_errors', 'On'); 

$db = "my_db"; 
$link = mysqli_connect("localhost", "user", "pass", "$db") or die(mysql_error()); 

$result = mysqli_query($link, "SELECT * FROM search_locations6 ORDER BY Population DESC") or die(mysql_error()); 
while($row = mysqli_fetch_array($result)) 
{ 
    $ii++; 
    $i++; 

    $data_array = array("city" => $row['city'],"county" => $row['county'],"region" => $row['region'],"country" => $row['country'],"url" => $row['url'],"combined" => $row['combined'],"city_lc" => $row['city_lc'],"population" => $row['Population'],"location" => array("lat" => $row['lat'],"lon" => $row['long'])); 

    //doing it in chunks, don't feel like changing heap sizes... etc. 
    if($i < 10000) 
    { 
     $json_data = '{"index":{"_id":"'.$ii.'"}}'; 
     $json_data .= "\n"; 
     $json_data .= json_encode($data_array); 
     $json_data .= "\n"; 
     file_put_contents('bulk.php', $json_data, FILE_APPEND); 
    } 
    else 
    { 
     exec('curl --fail --silent --show-error -XPOST \'localhost:9200/ff_search_locations2/1/_bulk?pretty&refresh\' --data-binary "@bulk.php"'); 
     unlink('bulk.php'); 
     unset($i); 
    } 
} 
+0

私はそれが働いていた以前の[リンク](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) –

答えて

0

ソート順はSuggestersクエリでサポートされていません。 Suggestersの全体のポイントはスピードであり、ミックスにソートを追加すると速度が遅くなります。

クエリにweightを追加してランキングを向上させることはできますが、セカンダリソートインデックスを追加することはできません。インデックスコードを見ると、あなたは​​フィールドとしてごcombinedフィールドのweightを追加することができます:あなたは二次ソートを探しているなら、私はあなたがsearch

EDITを使用することができます提案します。

`$data_array = array("city" => $row['city'],"county" => $row['county'],"region" => $row['region'],"country" => $row['country'],"url" => $row['url'],"combined" => array("input" => $row['combined'], "weight" => $row['Population']),"city_lc" => $row['city_lc'],"population" => $row['Population'],"location" => array("lat" => $row['lat'],"lon" => $row['long']));` 
+0

を発見しているはずのリファレンス!あなたの回答を更新することができれば、あなたの人口をあなたの補完タイプの体重として次のように追加してください: 'code' $ data_array = array(" city "=> $ row ['city']、" county $ row ['country']、 "url" => $ row ['url']、=> $ row ['county']、 $ row ['combined']、 "weight" => $ row ['Population'])、 "city_lc" => $ row ['city_lc']、 "population" $ row ['lat']、> lon "=> $ row ['long']));' code'それから私は '' Population 'それを正解とマークします。 –

+0

インデックスを作成していただきありがとうございます。私の答えを更新しました。 – NutcaseDeveloper

関連する問題