zoukankan      html  css  js  c++  java
  • elasticsearch-排序(六)

    默认排序

    默认查询是通过_source 准确性权重来排序

    字段排序

    {
        "query":{
            "match":{
            "productName":"床垫"
            }
        },
        "sort":{
            "price":"desc"
        }
    }

    结果

    {
        "took": 2,
        "timed_out": false,
        "_shards": {
            "total": 5,
            "successful": 5,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": 11,
            "max_score": null,
            "hits": [
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "1",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8",
                        "price": 13,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        13
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "2",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8",
                        "price": 12,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        12
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "14",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 14",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "8",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 8",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "9",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 9",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "10",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 10",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "12",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 12",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "6",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 6",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "7",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 7",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                },
                {
                    "_index": "blogs2",
                    "_type": "product",
                    "_id": "13",
                    "_score": null,
                    "_source": {
                        "productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8 13",
                        "price": 10,
                        "remark": "不错的床垫",
                        "tags": [
                            "家具",
                            "床垫",
                            "棉花"
                        ]
                    },
                    "sort": [
                        10
                    ]
                }
            ]
        }
    }

    可以发现_score为null并没有计算  因为计算是会消耗性能的 需要强制打开可以设置track_score为true

    多级排序

    {
        "query": {
            "match": {
                "productName": "床垫"
            }
        },
        "sort": [{
            "price": "desc"
        }, {
            "count": "asc"
        }]
    }

    Url搜索排序

  • 相关阅读:
    mysql自动补齐
    重置oracle 11G的system、sys密码《亲测》
    细说业务逻辑(前篇)<转>
    当我们把这么一个“狭义的概念”与“这个概念本身”等同起来时,误会、迷茫、困惑、不屑就出现了。
    设计模式就三个准则
    面向对象编程(OOP)的三大特点
    在计算机中,“透明”一词的理解。
    关于ArrayList中添加对象的一个有趣问题~~~~
    MyEclipse 代码自动提示功能失效 提示No Default Proposals 或 no completions available 的解决方法
    面向对象的三大基本特征
  • 原文地址:https://www.cnblogs.com/LQBlog/p/10435965.html
Copyright © 2011-2022 走看看