es:http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/get-doc.html
下一篇:http://my.oschina.net/qiangzigege/blog/264285
内容:
为了检索文档,我们使用同样的_index,_type和_id.
动作换成GET.
GET /website/blog/123?pretty
响应包含了熟悉的元数据,加上_source字段,source包含了原始的JSON对象。
{
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 1,
"found" : true,
"_source" : {
"title": "My first blog entry",
"text": "Just trying this out..."
"date": "2014/01/01"
}
}
响应包含 {"found": true}. 意味着文档找到了,如果我们找不存在的文档,found就会为false.
另外,HTTP的响应码可能为404,而不是202,我们可以传入-i参数(curl).
curl -i -XGET /website/blog/124?pretty
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=UTF-8
Content-Length: 83
{
"_index" : "website",
"_type" : "blog",
"_id" : "124",
"found" : false
}
检索一个文档的一部分
默认下,响应会返回整个文档,也许你只对title字段感兴趣,可以通过_source参数来过滤。
多个字段用逗号隔开。
GET /website/blog/123?_source=title,text
响应如下:
{
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 1,
"exists" : true,
"_source" : {
"title": "My first blog entry" ,
"text": "Just trying this out..."
}
}
或许你只想要source而不要meta数据。
GET /website/blog/123/_source
响应如下:
{
"title": "My first blog entry",
"text": "Just trying this out...",
"date": "2014/01/01"
}