2017-07-10 11 views
0

私は以下のようにElasticsearch 5.5に保存されたサンプルデータを持っています。私は、郵便配達員を使用して、match_all、gteなどに基づいてインデックスを作成し、検索することができます。弾性検索:評価に基づく並べ替え

{ 
    "name":"Apple", 
    "address": { 
    "city":"Cupertino", 
    "state":"CA", 
    "country":"USA" 
    }, 
    "rating":"4.9" 
} 

私は評価に基づいて、すべてのエンティティをソートする必要があるので、私は

{ 
    "query":{ 
    "match_all":{} 
    }, 
    "sort" : [ 
     { 
     "rating" : { 
      "order" : "desc" 
     } 
     } 
    ] 
} 

の下に使用しています。しかし、私は郵便配達

"type": "illegal_argument_exception", 
     "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [rating] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead." 

にエラー下の任意の提案を参照してください?

答えて

2

このフィールドで並べ替えを実行するには、評価フィールドを数値に変更する必要があるようです。

{ 
    "name":"Apple", 
    "address": { 
    "city":"Cupertino", 
    "state":"CA", 
    "country":"USA" 
    }, 
    "rating":4.9 
} 

そうでない場合、あなたは次のようにPUTマッピングAPIを使用して、既存のテキストフィールドにfielddataを有効にすることができます

PUT my_index/_mapping/my_type 
{ 
    "properties": { 
    "rating": { 
     "type":  "text", 
     "fielddata": true 
    } 
    } 
} 
関連する問題