您的位置:首页 > 其它

ES权威指南[官方文档学习笔记]-31 Retrieving a document

2014-05-13 00:00 543 查看
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"
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch