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

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"
}


 

转载于:https://my.oschina.net/qiangzigege/blog/264275

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值