脚本宝典收集整理的这篇文章主要介绍了ES排序介绍,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
GET /my-index-000001(索引名)/_seArch
{
"sort": [
{
"post_date": {
"order": "asc"
}
},
"user",
{
"name": "desc"
},
{
"age": "desc"
},
"_score"
],
"query": {
"term": {
"user": "kimchy"
}
}
}
当使用评分排序时,ES默认按照
倒序desc
排序,按照其他任意属性排序时默认为正序asc
排序
在下面的例子中,属性PRice在每个文档中都有多个数值,这个查询的结果会根据每个文档中价格的平均值按正序asc排序
PUT /my-index-000001/_doc/1?refresh
{
"product": "chocolate",
"price": [20, 4]
}
POST /_search
{
"query": {
"term": {
"product": "chocolate"
}
},
"sort": [
{
"price": {
"order": "asc",
"mode": "avg"
}
}
]
}
数字类型的值可以通过numeric_type
转成另一种类型的值。numeric_type
可接受以下类型的值 ["double", "long", "date", "date_nanos"
] 并且可用于跨多个数据流或索引的搜索
创建两个索引
PUT /index_double
{
"mappings": {
"properties": {
"field": { "type": "double" }
}
}
}
PUT /index_long
{
"mappings": {
"properties": {
"field": { "type": "long" }
}
}
}
两个索引中field
属性一个时double类型,一个是long类型;默认情况下无法使用filed
属性同时对两个索引进行排序。但是使用了numeric_type
后便可以
POST /index_long,index_double/_search
{
"sort" : [
{
"field" : {
"numeric_type" : "double"
}
}
]
}
在上面这个例子中,index_long
中的field
从long转换成double以与index-double
索引生成的值兼容。同样,也可以将float
字段转成long
类型,但这种情况下数值会向下取整(负数则为向上取整)
以上是脚本宝典为你收集整理的ES排序介绍全部内容,希望文章能够帮你解决ES排序介绍所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。