1.HEAD检查是否存在文档

  The API also allows to check for the existence of a document using HEAD

 HEAD index2/_doc/1

  结果:

 200 - OK

  

2.Source 过滤

  ①By default, the get operation returns the contents of the _source field unless you have used the stored_fields parameter or if the _source field is disabled. You can turn off _source retrieval by using the _source parameter。

  意思:

  默认情况下,返回的结果是_source。

  可以使用_source进行禁用。

 GET index2/_doc/1

  效果:

 {
"_index" : "index2",
"_type" : "_doc",
"_id" : "1",
"_version" : 12,
"_seq_no" : 11,
"_primary_term" : 4,
"found" : true,
"_source" : {
"name" : "tom1",
"age" : 20
}
}

  禁用:

 GET index2/_doc/1?_source=false

  结果:

 {
"_index" : "index2",
"_type" : "_doc",
"_id" : "1",
"_version" : 12,
"_seq_no" : 11,
"_primary_term" : 4,
"found" : true
}

  ②If you only need one or two fields from the complete _source, you can use the _source_includesand _source_excludes parameters to include or filter out the parts you need. This can be especially helpful with large documents where partial retrieval can save on network overhead. Both parameters take a comma separated list of fields or wildcard expressions. Example

  意思:

  对于大型的文档,只过滤自己需要的结果是合适的,降低网络开销

  可以使用参数进行控制source中的参数包含或者不包含。这种属于限制两边,留下中间的做法。

 GET twitter/_doc/1

  结果:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 6,
"_seq_no" : 5,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}

  过滤:

 GET twitter/_doc/1?_source_includes=u*,message&_source_excludes=post_date

  结果:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 6,
"_seq_no" : 5,
"_primary_term" : 1,
"found" : true,
"_source" : {
"message" : "trying out Elasticsearch",
"user" : "kimchy"
}
}

  ③If you only want to specify includes, you can use a shorter notation

 GET twitter/_doc/1?_source=message,user

  结果:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 6,
"_seq_no" : 5,
"_primary_term" : 1,
"found" : true,
"_source" : {
"message" : "trying out Elasticsearch",
"user" : "kimchy"
}
}

3.存储字段

  The get operation allows specifying a set of stored fields that will be returned by passing the stored_fields parameter. If the requested fields are not stored, they will be ignored. Consider for instance the following mapping

  意思是:

  可以通过设置参数,单独返回特定的字段

  下面是mapping:

 PUT tui
{
"mappings": {
"properties": {
"counter": {
"type": "integer",
"store": false
},
"tags": {
"type": "keyword",
"store": true
}
}
}
}

  结果:

 {
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "tui"
}

  添加文档:

 PUT tui/_doc/1
{
"counter" : 1,
"tags" : ["red","yellow"]
}

  获取:

 GET tui/_doc/1

  结果:

 {
"_index" : "tui",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"counter" : 1,
"tags" : [
"red",
"yellow"
]
}
}

  使用store_field:

 GET tui/_doc/1?stored_fields=tags,counter

  结果:

 {
"_index" : "tui",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"fields" : {
"tags" : [
"red",
"yellow"
]
}
}

  对于上面的结果,有些说明:

  Field values fetched from the document itself are always returned as an array. Since the counterfield is not stored the get request simply ignores it when trying to get the stored_fields.

  返回的结果作为一个数组,因为counter没有被存储,所以在获取stored_fields时或略。

4._source目录

  Use the /{index}/_source/{id} endpoint to get just the _source field of the document, without any additional content around it.

 GET twitter/_doc/1

  效果:

 {
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 6,
"_seq_no" : 5,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}

  使用_source

 GET twitter/_source/1

  效果:

 {
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}

006 GET API的更多相关文章

  1. Python 绝技 —— TCP服务器与客户端

    i春秋作家:wasrehpic 0×00 前言 「网络」一直以来都是黑客最热衷的竞技场.数据在网络中肆意传播:主机扫描.代码注入.网络嗅探.数据篡改重放.拒绝服务攻击……黑客的功底越深厚,能做的就越多 ...

  2. 006 使用SpringMVC开发restful API四--用户信息的修复与删除,重在注解的定义

    一:任务 1.任务 常用的验证注解 自定义返回消息 自定义校验注解 二:Hibernate Validator 1.常见的校验注解 2.程序 测试类 /** * @throws Exception * ...

  3. openstack api快速入门

    原文:http://my.oschina.net/guol/blog/105430 openstack官方有提供api供开发者使用,可以使用api做一些外围的小工具,用来简化对openstack的管理 ...

  4. jQuery EasyUI API 中文文档 - ComboGrid 组合表格

    jQuery EasyUI API 中文文档 - ComboGrid 组合表格,需要的朋友可以参考下. 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults ...

  5. 百度地图坐标转换API和地图API

    利用百度地图的服务将经纬度转换为米单位坐标 using System; using System.Collections.Generic; using System.Linq; using Syste ...

  6. 创建以 API 为中心的 Web 应用

    http://www.oschina.net/translate/creating-an-api-centric-web-application?from=20130818 正计划着要开始搞一个新的网 ...

  7. RESTful API Design With NodeJS & Restify

    http://code.tutsplus.com/tutorials/restful-api-design-with-nodejs-restify--cms-22637 The RESTful API ...

  8. 【高德地图API】从零开始学高德JS API(六)——坐标转换

    原文:[高德地图API]从零开始学高德JS API(六)——坐标转换 摘要:如何从GPS转到谷歌?如何从百度转到高德?这些都是小case.我们还提供,如何将基站cell_id转换为GPS坐标? --- ...

  9. Hbase多版本的读写(Shell&Java API版)

    Hbase是基于HDFS的NOsql数据库,它很多地方跟数据库差不多,也有很多不同的地方.这里就不一一列举了,不过Hbase有个版本控制的特性,这个特性在很多场景下都会发挥很大的作用.本篇就介绍下基于 ...

随机推荐

  1. 【Flask】 python学习第一章 - 2.0 视图方式和返回值

    路由参数与请求方式制定   ALT+回车 pycharm 快速导包  demo3  指定访问地址  与请求方式  #   给路由传入参数 使用尖括号 ,视图函数需要接收参数 @app.route(&q ...

  2. 数据库事务和锁(三)——INNODB_LOCKS, INNODB_LOCK_WAITS, INNODB_TRX表的简单介绍

    INNODB_LOCKS, INNODB_LOCK_WAITS, INNODB_TRX是MYSQL中事务和锁相关的表.通常我们遇到事务超时或锁相关问题时,直接运行下面SQL语句即可进行简单检查: -- ...

  3. linux 的常用命令(1)

    1.关于ls [选项][目录名] -a  列出包括.a开头的隐藏文件的所有文件-A  通-a,但不列出"."和".."-l  列出文件的详细信息-c  根据ct ...

  4. redis的过期策略都有哪些?内存淘汰机制都有哪些?手写一下LRU代码实现?

    redis的过期策略都有哪些? 设置过期时间: set key 的时候,使用expire time,就是过期时间.指定这个key比如说只能存活一个小时?10分钟?指定缓存到期就会失效. redis的过 ...

  5. 图中长度为k的路径的计数

    题意 给出一个有向图,其中每条边的边长都为1.求这个图中长度恰为 $k$ 的路劲的总数.($1 \leq n \leq 100, 1 \leq k\leq 10^9$) 分析 首先,$k=1$ 时答案 ...

  6. SpringBoot第一次案例(以及jar包的生成)

    一.Springboot简介 Springboot框架就用于简化Spring应用的开发,约定大于配置,去繁从简.从以往的“Spring全家桶时代”正式过渡到”Spring boot,J2EE一站式解决 ...

  7. NISP二级笔记(一) 信息安全管理

    ISO27001 信息安全管理体系要求 ISO27002 信息安全控制措施(实用规则) ISO27003 信息安全管理体系实施指南 ISO27004 信息安全管理测量 ISO27005 信息安全风险管 ...

  8. learning AWT Jrame

    import java.awt.*; public class FrameTest { public static void main(String[] args) { var f = new Fra ...

  9. Ubuntu 系统安装教程

  10. javascript生成表格增删改查 JavaScript动态改变表格单元格内容 动态生成表格 JS获取表格任意单元格 javascript如何动态删除表格某一行

    jsp页面表格布局Html代码 <body onload="show()"> <center> <input type="text" ...