当前位置:   article > 正文

ES DSL搜索 - 过滤器_搜索结果语言过滤器是什么意思

搜索结果语言过滤器是什么意思

1 介绍

主要介绍索引请求的基础API操作,使用postman进行请求,接口请求的前缀地址统一为elasticsearch 部署IP地址+端口号(例如 http://192.168.51.4:9200 。

统一请求地址:

POST /search_demo/_doc/_search
  • 1

过滤器,是对搜索出来的结果进行数据过滤。不会到es的库里面去搜,不会去计算文档的相关度分数,所以过滤的性能会比较高,过滤器可以和全文搜索结合在一起使用。

2 post_filter

post_filter 元素是一个顶层元素,只会对搜索结果进行过滤。不会计算数据的匹配度相关性分数,不会根据分数去排序,query则相反,会计算分数,也会按照分数去排序。

使用场景:

  • query:根据用户搜索条件检索匹配记录
  • post_filter:用户查询后,对结果数据的筛选

例子查询:查询账户金额大于80,小于160的用户

  • gte:大于等于
  • lte:小于等于
  • gt:大于
  • lt:小于

传递JSON数据

{
    "query": {
        "match": {
            "desc": "好的"
        }
    },
    "post_filter": {
        "range": {
            "money": {
                "gt": 60,
                "lt": 1000
            }
        } 
    }
  
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

请求结果

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 7,
            "relation": "eq"
        },
        "max_score": 3.0979095,
        "hits": [
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1005",
                "_score": 3.0979095,
                "_source": {
                    "id": 1005,
                    "age": 25,
                    "username": "switch",
                    "nickname": "switch游戏机",
                    "money": 155.8,
                    "desc": "好的游戏,才会有人购买,比如塞尔达",
                    "sex": 1,
                    "birthday": "1989-03-14",
                    "face": "http://www.p2pi.cn/static/img/1005_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1003",
                "_score": 0.37556386,
                "_source": {
                    "id": 1003,
                    "age": 20,
                    "username": "youTuTu",
                    "nickname": "涡轮增压",
                    "money": 66.8,
                    "desc": "极限的速度是需要涡轮增压的",
                    "sex": 1,
                    "birthday": "1996-01-14",
                    "face": "http://www.p2pi.cn/static/img/1003_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1012",
                "_score": 0.36424035,
                "_source": {
                    "id": 1012,
                    "age": 19,
                    "username": "youzi",
                    "nickname": "youzi",
                    "money": 188.8,
                    "desc": "永远的神",
                    "sex": 1,
                    "birthday": "1980-08-14",
                    "face": "http://www.p2pi.cn/static/img/1012_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1002",
                "_score": 0.35254776,
                "_source": {
                    "id": 1002,
                    "age": 19,
                    "username": "Ailun",
                    "nickname": "进击的巨人",
                    "money": 77.8,
                    "desc": "艾伦是会变成真正的巨人的",
                    "sex": 1,
                    "birthday": "1993-01-24",
                    "face": "http://www.p2pi.cn/static/img/1002_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1011",
                "_score": 0.27665582,
                "_source": {
                    "id": 1011,
                    "age": 31,
                    "username": "petter",
                    "nickname": "皮特",
                    "money": 180.8,
                    "desc": "皮特的姓氏好像是彼得",
                    "sex": 1,
                    "birthday": "1989-08-14",
                    "face": "http://www.p2pi.cn/static/img/1011_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1009",
                "_score": 0.252381,
                "_source": {
                    "id": 1009,
                    "age": 22,
                    "username": "lucy",
                    "nickname": "露西",
                    "money": 96.8,
                    "desc": "露西是一只很聪明的cat",
                    "sex": 1,
                    "birthday": "1998-07-14",
                    "face": "http://www.p2pi.cn/static/img/1009_face.png"
                }
            },
            {
                "_index": "search_demo",
                "_type": "_doc",
                "_id": "1001",
                "_score": 0.18093815,
                "_source": {
                    "id": 1001,
                    "age": 18,
                    "username": "Tic",
                    "nickname": "飞翔的荷兰号",
                    "money": 88.8,
                    "desc": "我在p2pi网站解决项目中遇到的问题,学习到了很多知识",
                    "sex": 0,
                    "birthday": "1992-12-24",
                    "face": "http://www.p2pi.cn/static/img/1001_face.png"
                }
            }
        ]
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138

3 相关信息

  • 博文不易,辛苦各位猿友点个关注和赞,感谢
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/750629
推荐阅读
相关标签
  

闽ICP备14008679号