我在Elasticsearch 5.5中存储了类似于下面的示例数据。我可以使用postman创建索引,基于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."
有什么建议吗?
答案 0 :(得分: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
}
}
}