跳到主要内容

十四、Elasticsearch 教程: 搜索 API

本章节,我们要学习和介绍的 API 用于在 Elasticsearch 中搜索内容

我们可以通过以查询字符串作为参数或发送请求消息正文中的查询发送获取请求来进行搜索

多索引

Elasticsearch 允许我们搜索所有的索引或某些特定索引中存在的文档

例如,如果我们要搜索昵称中包含 的所有文档,可以发起下面这种请求

GET http://localhost:9200/_search?pretty&q=nickname:飞

返回响应

{
"took" : 19,
"timed_out" : false,
"_shards" : {
"total" : 15,
"successful" : 15,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "user_admin",
"_type" : "user",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"nickname" : "站长",
"description" : "pottercoding.cn 程序员波特,程序员编程资料站 ,教程 ",
"street" : "东四十条",
"city" : "Beijing",
"state" : "Beijing",
"zip" : "100007",
"location" : [
116.432727,
39.937732
],
"money" : 5201814,
"tags" : [
"PHP",
"Python"
],
"vitality" : "9.0"
}
}
]
}