简介
该API用于在Elasticsearch中搜索内容。用户可以通过发送带有查询字符串作为参数的get请求进行搜索,或者可以在发布请求的消息正文中发布查询。搜索 api 主要是多索引、多类型的。
多索引
Elasticsearch允许我们搜索所有索引或某些特定索引中存在的文档。
GET /_all/_search?q=city:Meerut
返回:
{ "took": 1, "timed_out": false, "_shards": { "total": 4, "successful": 4, "skipped": 0, "Failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.2876821, "hits": [ { "_index": "school", "_id": "1", "_score": 0.2876821, "_source": { "name": "City School", "description": "ICSE", "street": "West End", "city": "Meerut", "state": "UP" } } ] } }
URI搜索
序号 | 参数及说明 |
---|---|
1 |
Q 此参数用于指定查询字符串 |
2 |
lenient 此参数用于指定查询字符串。只要将此参数设置为 true,就可以忽略基于 Formatbased 的错误。默认情况下它是假的。 |
3 |
fields 此参数用于指定查询字符串 |
4 |
sort 我们可以通过使用这个参数得到排序的结果,这个参数的可能值是fieldName, fieldName:asc/ fieldName:desc |
5 |
timeout |
6 |
terminate_after |
7 |
from 要返回的命中数的起始索引。默认为0。 |
8 |
size 它表示要返回的命中数,默认值为10。 |
请求正文搜索
POST /schools/_search { "query":{ "query_string":{ "query":"City" } } }
返回:
{ "took": 0, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "Failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.2876821, "hits": [ { "_index": "school", "_id": "1", "_score": 0.2876821, "_source": { "name": "City School", "description": "ICSE", "street": "West End", "city": "Meerut", "state": "UP" } } ] } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。