根据某个字段进行排序,该字段的type如果为keyword,会导致排序失效,查看映射,可以看到sort中的skuPrice为字符串,改成double,可以看到sort中的值为数字。
在索引中skuPrice为keyword类型(字符串)
修改为数值类型double 即可排序,亲试成功
修改方法:
创建一个新的索引gulimall_product2,
可以使用查原索引库,去掉索引库名称,修改skuPrice的type为double
PUT gulimall_product2
{
"mappings": {
"properties": {
"attrs": {
"type": "nested",
"properties": {
"attrId": {
"type": "long"
},
"attrName": {
"type": "keyword"
},
"attrValue": {
"type": "keyword"
}
}
},
"brandId": {
"type": "long"
},
"brandImg": {
"type": "keyword"
},
"brandName": {
"type": "keyword"
},
"catalogId": {
"type": "long"
},
"catalogName": {
"type": "keyword"
},
"catelogId": {
"type": "long"
},
"hasStock": {
"type": "boolean"
},
"hotScore": {
"type": "long"
},
"saleCount": {
"type": "long"
},
"skuId": {
"type": "long"
},
"skuImg": {
"type": "keyword"
},
"skuPrice": {
"type": "double"
},
"skuTitle": {
"type": "text",
"analyzer": "ik_smart"
},
"spuId": {
"type": "keyword"
}
}
}
}
导入前索引库的数据
POST _reindex
{
"source": {
"index": "gulimall_product"
},
"dest": {
"index": "gulimall_product2"
}
}
亲试成功