《Elastic Stack 实战手册》——三、产品能力——3.2.核心应用场景——3.2.1.企业搜索 (2) https://developer.aliyun.com/article/1231679
用户可以按自己的需求,在搜索时设置搜索字段、结果字段、字段权重、字段值权重、过滤、排序、分页、构面、高亮显示等。
如下代码设置返回第一页,每页一条内容:
curl -X POST http://localhost:3002/api/ws/v1/search \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "query": "denali", "page": { "size": 1, "current": 1 } }'
如下代码设置按 square_km 逆序,date_established 顺序排序:
curl -X POST http://localhost:3002/api/ws/v1/search \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "query": "denali", "sort": [ { "square_km": "desc" }, { "date_established": "asc" } ] }'
如下代码设置在字段 Title 和 Description 中搜索,Title 的权重为10:
curl -X POST http://localhost:3002/api/ws/v1/search \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "query": "denali", "search_fields": { "title": { "weight": 10 }, "description": {} } }'
如下代码根据字段 world_heritage_site 的值设置权重,当字段值为 true 时权重为 10:
curl -X GET 'https://[instance id].ent-search.[region].[provider].cloud.es.io/api/as/v1/engines/national-parks-demo/search' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \ -d '{ "query": "old growth", "boosts": { "world_heritage_site": [ { "type": "value", "value": "true", "operation": "multiply", "factor": 10 } ] } }
App Search 支持对查询进行加 tag 并按 tag 进行过滤查询:
curl -X GET 'https://[instance id].ent-search.[region].[provider].cloud.es.io/api/as/v1/engines/national-parks-demo/search' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \ -d '{ "query": "everglade", "analytics": { "tags": [ "i-am-a-tag" ] } }' curl -X GET 'https://[instance id].ent-search.[region].[provider].cloud.es.io/api/as/v1/engines/national-parks-demo/analytics/queries' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer private-namt1hkv7ttsawuo452sxi6s' \ -d '{ "filters": { "tag": "i-am-a-tag" } }'
支持对查询结果的控制
App Search 支持对查询结果直接进行控制。如下图,点击星号或者直接拖动结果可重新对查询结果进行排序,点击眼睛图标可隐藏查询结果。当然,所有操作也都是可以使用 API 进行设定,详情见 Curations API。
《Elastic Stack 实战手册》——三、产品能力——3.2.核心应用场景——3.2.1.企业搜索 (4) https://developer.aliyun.com/article/1231677