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搜索排序

  • 相关阅读:
    大数据DDos检测——DDos攻击本质上是时间序列数据,t+1时刻的数据特点和t时刻强相关,因此用HMM或者CRF来做检测是必然! 和一个句子的分词算法CRF没有区别!
    什么是私有密钥密码技术——密钥加密算法采用同一把密钥进行加密和解密
    条件随机场——时间序列(句子单词序列也算),其特征函数必须要考虑前一刻的数据
    隐形马尔可夫模型——前向算法就是条件概率
    MySQL添加字段和修改字段的方法
    shell脚本操作mysql数据库
    mysql 如何修改、添加、删除表主键
    shell按行合并文件
    MySQL主键添加/删除
    MySQL 添加列,修改列,删除列
  • 原文地址:https://www.cnblogs.com/LQBlog/p/10435965.html
Copyright © 2011-2022 走看看