Now let’s start with some simple searches. There are two basic ways to run searches: one is by sending search parameters through the REST request URIand the other by sending them through the REST request body. The request body method allows you to be more expressive and also to define your searches in a more readable JSON format. We’ll try one example of the request URI method but for the remainder of this tutorial, we will exclusively be using the request body method.

现在让我们从一些简单的搜索开始吧。运行搜索有两种基本方法:一种是通过REST请求URI发送搜索参数,另一种是通过REST请求体发送搜索参数。请求体方法允许您更具表现力,并以更易读的JSON格式定义搜索。我们将尝试一个请求URI方法的示例,但是对于本教程的其余部分,我们将专门使用请求体方法。
 
The REST API for search is accessible from the _search endpoint. This example returns all documents in the bank index:
可以从_search端点访问用于搜索的REST API。此示例返回银行索引中的所有文档:
curl -X GET "localhost:9200/bank/_search?q=*&sort=account_number:asc&pretty"

Let’s first dissect the search call. We are searching (_search endpoint) in the bank index, and the q=* parameter instructs Elasticsearch to match all documents in the index. The sort=account_number:asc parameter indicates to sort the results using the account_number field of each document in an ascending order. The pretty parameter, again, just tells Elasticsearch to return pretty-printed JSON results.

让我们首先剖析搜索电话。我们在银行索引中搜索(_search endpoint),q = *参数指示Elasticsearch匹配索引中的所有文档。 sort = account_number:asc参数指示使用升序中的每个文档的account_number字段对结果进行排序。漂亮的参数再次告诉Elasticsearch返回漂亮的JSON结果。
 
And the response (partially shown):部分展示
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"skipped" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : null,
"hits" : [ {
"_index" : "bank",
"_type" : "_doc",
"_id" : "",
"sort": [],
"_score" : null,
"_source" : {"account_number":,"balance":,"firstname":"Bradshaw","lastname":"Mckenzie","age":,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"bradshawmckenzie@euron.com","city":"Hobucken","state":"CO"}
}, {
"_index" : "bank",
"_type" : "_doc",
"_id" : "",
"sort": [],
"_score" : null,
"_source" : {"account_number":,"balance":,"firstname":"Amber","lastname":"Duke","age":,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
}, ...
]
}
}

As for the response, we see the following parts:

1、took – time in milliseconds for Elasticsearch to execute the search
  Elasticsearch执行搜索的时间(以毫秒为单位)

2、timed_out – tells us if the search timed out or not
  告诉我们搜索是否超时(默认10秒)
3、_shards - tells us how many shards were searched, as well as a count of the successful/failed searched shards
  告诉我们搜索了多少个分片,以及搜索成功/失败分片的数量

4、 hits – search results        
       搜索结果
5、hits.hits – actual array of search results (defaults to first 10 documents)       

  实际的搜索结果数组(默认为前10个文档)

6、hits.sort - sort key for results (missing if sorting by score)         

   对结果进行排序(如果按分数排序则丢失)

7、 hits._score and max_score - ignore these fields for now
  暂时忽略这些字段
 
 Here is the same exact search above using the alternative request body method:
以下是使用替代请求正文方法的上述完全相同的搜索:
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
'

The difference here is that instead of passing q=* in the URI, we provide a JSON-style query request body to the _search API. We’ll discuss this JSON query in the next section.

这里的区别在于,我们不是在URI中传递q = *,而是向_search API提供JSON样式的查询请求体。我们将在下一节讨论这个JSON查询。
 
It is important to understand that once you get your search results back, Elasticsearch is completely done with the request and does not maintain any kind of server-side resources or open cursors into your results. This is in stark contrast to many other platforms such as SQL wherein you may initially get a partial subset of your query results up-front and then you have to continuously go back to the server if you want to fetch (or page through) the rest of the results using some kind of stateful server-side cursor.
重要的是要理解,一旦您获得了搜索结果,Elasticsearch就完全完成了请求,并且不会在结果中维护任何类型的服务器端资源或打开游标。这与SQL等许多其他平台形成鲜明对比,其中您可能最初预先获得查询结果的部分子集,然后如果要获取(或翻页)其余的则必须连续返回服务器使用某种有状态服务器端游标的结果。
 
 
 
 

(十五)The Search API的更多相关文章

  1. 微信小程序把玩(三十五)Video API

    原文:微信小程序把玩(三十五)Video API 电脑端不能测试拍摄功能只能测试选择视频功能,好像只支持mp4格式,值得注意的是成功之后返回的临时文件路径是个列表tempFilePaths而不是tem ...

  2. Expo大作战(三十五)--expo sdk api之Location!

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  3. Expo大作战(二十五)--expo sdk api之Admob

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  4. Salesforce LWC学习(三十五) 使用 REST API实现不写Apex的批量创建/更新数据

    本篇参考: https://developer.salesforce.com/docs/atlas.en-us.224.0.api_rest.meta/api_rest/resources_compo ...

  5. 十五、polygon API

    How polygons are handled internally The five basic polygonal API classes Construction History and Tw ...

  6. salesforce零基础学习(八十五)streaming api 简单使用(接近实时获取你需要跟踪的数据的更新消息状态)

    Streaming API参考链接: https://trailhead.salesforce.com/en/modules/api_basics/units/api_basics_streaming ...

  7. Spring学习十五----------Spring AOP API的Pointcut、advice及 ProxyFactoryBean相关内容

    © 版权声明:本文为博主原创文章,转载请注明出处 实例: 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4. ...

  8. Java笔记(二十五)……其他常用API

    System类 工具类全部都是静态方法 常用方法 获取系统属性信息 static PropertiesgetProperties() static StringgetProperty(String k ...

  9. 如鹏网学习笔记(十五)ASP.NET MVC核心基础笔记

    一.ASP.Net MVC简介 1,什么是ASP.NET MVC? HttpHandler是ASP.net的底层机制,如果直接使用HttpHandler进行开发难度比较大.工作量大.因此提供了ASP. ...

  10. ES系列十五、ES常用Java Client API

    一.简介 1.先看ES的架构图 二.ES支持的客户端连接方式 1.REST API http请求,例如,浏览器请求get方法:利用Postman等工具发起REST请求:java 发起httpClien ...

随机推荐

  1. centos7下vim8.1的编译安装教程

    之前安装YouCompleteMe的时候遇到vim版本不兼容的问题,看网上说是需要将vim版本提升到8.0及以上,然后就开始安装最新版本的vim,安装过程中的遇到了不少问题主要集中在配置方面和缺少插件 ...

  2. iBinary C++STL模板库关联容器之map/multimap

    目录 一丶关联容器map/multimap 容器 二丶代码例子 1.map的三种插入数据的方法 3.map集合的遍历 4.验证map集合数据是否插入成功 5.map数据的查找 6.Map集合删除元素以 ...

  3. Markdown 语法详尽笔记大全 2019

    目录  0.介绍  1.快捷键  2.基本语法  2.1 分级标题 # 写法1 # 写法2 上下文标题  2.2 字体设置斜体.粗体.删除线 _*~  2.3 分割线 --- 或 ***  2.4 引 ...

  4. Powerdesigner逆向工程64位Oracle数据库

    Powerdesigner老版本不支持64位Client,新版本弄不到破解码 解决方法,用Powerdesigner+32位Oracle Clent访问64位Oracle Server 遇到的坑分享下 ...

  5. 2013年第四届蓝桥杯javaB组 试题 答案 解析

    1.世纪末的星期 曾有邪教称1999年12月31日是世界末日.当然该谣言已经不攻自破. 还有人称今后的某个世纪末的12月31日,如果是星期一则会.... 有趣的是,任何一个世纪末的年份的12月31日都 ...

  6. C#设计模式之二十二备忘录模式(Memento Pattern)【行为型】

    一.引言 今天我们开始讲“行为型”设计模式的第十个模式,该模式是[备忘录模式],英文名称是:Memento Pattern.按老规矩,先从名称上来看看这个模式,个人的最初理解就是对某个对象的状态进行保 ...

  7. vue 如何点击按钮返回上一页

    1,vue 如何点击按钮返回上一页呢? 这是vue挂载的范围html代码 <div @click="goOff()">返回</div> 下面是点击返回的方法 ...

  8. 【20190228】JavaScript-获取子元素

    在写JavaScript的时候发现了一个获取子节点的坑,如以下的html结构 <div id="parent"> <div>1</div> &l ...

  9. java StringBuilder 和 StringBuffer

    1, 相对于 String 来说, StringBuilder 和 StringBuffer 均是可变的 2, StringBuilder 线程不安全, StringBuffer 线程安全 3, 运行 ...

  10. Node的简介

    从开始学习node到现在已经有半年多了,中间没有做过什么实际工作中的项目,所以感觉自己的知识有些匮乏,但是我还是要写这些文章,因为工作中的需要用node来开发后台环境,再加上我对这些知识记得不多,都是 ...