在具体的学习前,我还是决定学一下,REST风格中在ES中的约定。

一:索引

1.多重索引

  先准备数据:

    如果不小心,json里的值写错了,修改过来,重新执行即可。

 PUT index1/_doc/1
{
"name":"tom1"
}
PUT index2/_doc/1
{
"name":"tom1",
"age":20
}
PUT index3/_doc/1
{
"name":"tom3",
"address":"tom3 is good ,in beijing"
}

  多重索引:

  POST /index1,index2,index3/_search
{
"query":{
"query_string": {
"query":"tom1"
}
}
}

  结果:

    返回index1,index2,index3中包含tom1的Json对象,如果只输入tom,则是查询不到值的。

 {
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.6931472,
"hits" : [
{
"_index" : "index2",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.6931472,
"_source" : {
"name" : "tom1",
"age" : 20
}
},
{
"_index" : "index1",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "tom1"
}
}
]
}
}

2._all关键字

  所有的索引

  POST _all/_search
{
"query":{
"query_string": {
"query":"tom3"
}
}
}

  效果:

 {
"took" : 19,
"timed_out" : false,
"_shards" : {
"total" : 6,
"successful" : 6,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "index3",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "tom3",
"address" : "tom3 is good ,in beijing"
}
}
]
}
}

3.通配符的使用

  通配符主要有:* ,+ ,-

  *:

  index开头的索引中查找有tom3的JSON对象。

  POST /index*/_search
{
"query":{
"query_string": {
"query":"tom3"
}
}
}

  -:

  不包含index2的索引中查找

 POST /index*,-index2/_search
{
"query":{
"query_string": {
"query": "tom1"
}
}
}

4.URL查询字符串参数

  ①ignore_unavailable:如果不存在索引,一个或者多个,都不会停止,继续运行

 POST /index1,index4/_search
{
"query":{
"query_string": {
"query": "tom1"
}
}
}

  则有问题:

 {
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [index4]",
"resource.type" : "index_or_alias",
"resource.id" : "index4",
"index_uuid" : "_na_",
"index" : "index4"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [index4]",
"resource.type" : "index_or_alias",
"resource.id" : "index4",
"index_uuid" : "_na_",
"index" : "index4"
},
"status" : 404
}

  加上参数:

 POST /index1,index4/_search?ignore_unavailable=true
{
"query":{
"query_string": {
"query": "tom1"
}
}
}

  效果:

 {
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "index1",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "tom1"
}
}
]
}
}

  ②allow_no_indices:如果没有通配符指定的索引,true可以防止报错

 POST /mmm*/_search?allow_no_indices=true
{
"query":{
"query_string": {
"query": "tom1"
}
}
}

  效果:

 {
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 0,
"successful" : 0,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [ ]
}
}

二:响应

1.响应信息过滤

  数据:

 {
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "index1",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "tom1"
}
},
{
"_index" : "index2",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "tom1",
"age" : 20
}
}
]
}
}

  过滤:

 POST /index1,index2/_search?filter_path=hits.hits._source.age
{
"query":{
"query_string": {
"query": "tom1"
}
}
}

  效果:

 {
"hits" : {
"hits" : [
{
"_source" : {
"age" : 20
}
}
]
}
}

2.漂亮的结果

 Post /index1/_search?pretty=true
{
"query":{
"match_all": {}
}
}

004 API约定的更多相关文章

  1. ECharts之force力导向布局图——数据源说明及后端API约定

    Echarts ? 关于 Echarts 请移步这里 force 力导向图 实现方式,如: function require_EC () { require( [ 'echarts', //载入for ...

  2. elasticsearch api约定

    elasticsearch REST API 使用JSON通过HTTP协议传输. 本约定贯穿整个REST API,除非有特别的说明. 一.多重索引 大多数APIs引用到一个index参数来在多个索引中 ...

  3. elasticsearch 第四篇(API约定)

    对多个indices进行操作 es中大多resetapi支持请求多个index, 例如”test1,test2,test3”,index也可以使用通配符, 例如”test*“, 还可以使用+,-来包含 ...

  4. EF Code First教程-02.1 Fluent API约定配置

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  5. Entity Framework 5.0系列之约定配置

    Code First之所以能够让开发人员以一种更加高效.灵活的方式进行数据操作有一个重要的原因在于它的约定配置.现在软件开发越来复杂,大家也都试图将软件设计的越来越灵活,很多内容我们都希望是可配置的, ...

  6. 【转】Entity Framework 5.0系列之约定配置

    Code First之所以能够让开发人员以一种更加高效.灵活的方式进行数据操作有一个重要的原因在于它的约定配置.现在软件开发越来复杂,大家也都试图将软件设计的越来越灵活,很多内容我们都希望是可配置的, ...

  7. ASP.NET Web API queryString访问的一点总结

    自从开始使用ASP.NET Web API,各种路由的蛋疼问题一直困扰着我,相信大家也都一样. Web API的路由配置与ASP.MVC类似,在App_Start文件夹下,有一个WebApiConfi ...

  8. 使用Etherscan API通过区块号获取块及叔块奖励

    本文原文链接 点击这里获取Etherscan API 中文文档(完整版) 完整内容排版更好,推荐读者前往阅读. 区块(Blocks) 区块相关的 API,接口的参数说明请参考Etherscan API ...

  9. Etherscan API 中文文档-交易以及检查交易收据状态

    本文原文链接 点击这里获取Etherscan API 中文文档(完整版) 完整内容排版更好,推荐读者前往阅读. 交易(Transaction) 交易相关的 API,接口的参数说明请参考Ethersca ...

随机推荐

  1. 迷你商城后台管理系统————stage2核心代码实现

    应用程序主函数接口 @SpringBootApplication(scanBasePackages = {"org.linlinjava.litemall.db", "o ...

  2. 第五次个人作业——Alpha测试

    这个作业属于哪个课程 课程链接 这个作业要求在哪里 作业要求 团队名称 巧克力王子与六个小矮人 一.测试项目博客地址 项目名 团队名 博客地址 项目发布地址 西柚排课王 西柚排课王 https://w ...

  3. python蟒蛇绘制的代码以及目前还不知道怎么用的RGB颜色对照表

    #PythonDraw.py import turtle#引入海龟库 turtle.setup(650,350,200,200)#确定窗口大小,长650,高350,确定窗口位置,距离电脑左上角200, ...

  4. web 错误代码解析

    404表示文件或资源未找到java WEB常见的错误代码1.1xx-信息提示:这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个1xx响应.100-继续.101-切换协议.2. ...

  5. Win10 系统 Mysql 安装

    对于本地开发环境,小型的 Mysql 比较适合本地学习. 本文环境 win10 + mysql8 1.下载 去 Mysql 官网下载安装包 - https://dev.mysql.com/downlo ...

  6. Django上传文件和修改date格式

    上传大文件的时候: 修改date数据:

  7. linux autofs自动挂载

    autofs:自动挂载器 自动挂载器是一个监视目录的守护进程,并在目标子目录被引用时,自动执行预定义的NFS挂载 自动挂载器由autofs服务脚本管理 自动挂载器由auto.master配置文件进行配 ...

  8. Python中pass、continue、break、exit()的区别

    pass :不做任何事情,只起到占位的作用 continue: 跳出本次循环 break:结束循环 exit():结束整个程序 由于continue和break较简单,这里就不给出代码

  9. 0.Pycharm安装

    以windows版本举例: 1.首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载P ...

  10. [NgRx] NgRx Data Fetching Solution - How to Load Data Only If Needed

    We have a reoslver, which everytime we want visit '/courses' route, it will be triggered, then api w ...