elasticsearch Elasticsearch:根据评级进行排序
我在Elasticsearch 5.5中存储了一个样本数据,如下所示。我可以创建索引,搜索的基础上匹配,gte等使用邮递员
elasticsearch Elasticsearch:根据评级进行排序,
elasticsearch,postman,
elasticsearch,Postman,我在Elasticsearch 5.5中存储了一个样本数据,如下所示。我可以创建索引,搜索的基础上匹配,gte等使用邮递员 { "name":"Apple", "address": { "city":"Cupertino", "state":"CA", "country":"USA" }, "rating":"4.9" } 我需要根据评级对所有实体进行排序,因此我在下面使用 { "query":{ "match_all":{} },
{
"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."
有什么建议吗?似乎需要将“评级”字段更改为数字,以便在此字段上执行排序
{
"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
}
}
}
似乎需要将rating字段更改为numeric,以便在此字段上执行排序
{
"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
}
}
}