赞
踩
主要介绍索引请求的基础API操作,使用postman进行请求,接口请求的前缀地址统一为elasticsearch 部署IP地址+端口号(例如 http://192.168.51.4:9200 。
统一请求地址:
POST /search_demo/_doc/_search
过滤器,是对搜索出来的结果进行数据过滤。不会到es的库里面去搜,不会去计算文档的相关度分数,所以过滤的性能会比较高,过滤器可以和全文搜索结合在一起使用。
post_filter
元素是一个顶层元素,只会对搜索结果进行过滤。不会计算数据的匹配度相关性分数,不会根据分数去排序,query则相反,会计算分数,也会按照分数去排序。
使用场景:
例子查询:查询账户金额大于80,小于160的用户
传递JSON数据
{ "query": { "match": { "desc": "好的" } }, "post_filter": { "range": { "money": { "gt": 60, "lt": 1000 } } } }
请求结果
{ "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" } } ] } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。