7、Multi Get API(Multi Get API)

multi GET API 允许你一次性获取多个文档,你需要指定docs数组,其中包含了所有你需要查询的文档,每个查询结构至少包含索引,类型和文档id。如果操作过程中遇到错误将会返回错误信息。返回的结果与 GET API 的结果结构类似。

如下例所示:

GET /_mget
{
    "docs" : [
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "1"
        },
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "2"
        }
    ]
}

mget 也可以仅仅针对一个索引使用:

GET /test/_mget
{
    "docs" : [
        {
            "_type" : "_doc",
            "_id" : "1"
        },
        {
            "_type" : "_doc",
            "_id" : "2"
        }
    ]
}

或者针对一个类型使用:

GET /test/_doc/_mget
{
    "docs" : [
        {
            "_id" : "1"
        },
        {
            "_id" : "2"
        }
    ]
}

如果仅指定id参数的话,也可以用一个id数组来指定:

GET /test/_doc/_mget
{
    "ids" : ["1", "2"]
}

7.1 字段过滤(Source filtering)

默认情况下,将为每个文档(如果存储)返回_source中的所有字段。和 get API 类似,您可以通过设置_source 参数指定_source 中需要返回的字段。您也可以用 url 参数中的_source_source_include_source_exclude来设置,如:

GET /_mget
{
    "docs" : [
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "1",
            "_source" : false
        },
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "2",
            "_source" : ["field3", "field4"]
        },
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "3",
            "_source" : {
                "include": ["user"],
                "exclude": ["user.location"]
            }
        }
    ]
}

7.2 字段(Fileds)

为了节省内存和存储空间,你可能不启用_source,使用store保存部分字段。指定为stored 的字段可以通过stored_fields字段获得:

GET /_mget
{
    "docs" : [
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "1",
            "stored_fields" : ["field1", "field2"]
        },
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "2",
            "stored_fields" : ["field3", "field4"]
        }
    ]
}

或者,在url中指定 stored_fields,作为所有文档默认查询的字段:

GET /test/_doc/_mget?stored_fields=field1,field2
{
    "docs" : [
        {
            "_id" : "1" 【1】
        },
        {
            "_id" : "2",
            "stored_fields" : ["field3", "field4"] 【2】
        }
    ]
}

【1】:返回field1和field2字段

【2】:返回field3和field4字段

7.3 路由(Routing)

您也可以指定 routing 参数

GET /_mget?routing=key1
{
    "docs" : [
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "1",
            "routing" : "key2"
        },
        {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "2"
        }
    ]
}

test/_doc/2 文档会使用key1作为路由值,test/_doc/1文档会使用key2作为路由值

7.4 安全(Security)

查阅URL-based access control

elasticsearch6.7 05. Document APIs(8)Multi Get API的更多相关文章

  1. elasticsearch6.7 05. Document APIs(2)Index API

    Single document APIs Index API Get API Delete API Update API Multi-document APIs Multi Get API Bulk ...

  2. elasticsearch6.7 05. Document APIs(10)Reindex API

    9.REINDEX API Reindex要求为源索引中的所有文档启用_source. reindex 不会配置目标索引,不会复制源索引的设置.你需要在reindex之前先指定mapping,分片数量 ...

  3. elasticsearch6.7 05. Document APIs(6)UPDATE API

    5. UPDATE API 更新操作可以使用脚本来更新.更新的时候会先从索引中获取文档数据(在每个分片中的集合),然后运行脚本(使用可选的脚本语言和参数),再果进行索引(还允许删除或忽略该操作).它使 ...

  4. elasticsearch6.7 05. Document APIs(5)Delete By Query API

    4.Delete By Query API _delete_by_query API可以删除某个匹配条件的文档: POST twitter/_delete_by_query { "query ...

  5. elasticsearch6.7 05. Document APIs(9)Bulk API

    8.Bulk API 可以把多个index或delete操作放在单个bulk API中执行.这样可以极大地提高索引速度. /_bulkAPI使用如下的JSON结构: action_and_meta_d ...

  6. elasticsearch6.7 05. Document APIs(7)Update By Query API

    6.Update By Query API _update_by_query 接口可以在不改变 source 的情况下对 index 中的每个文档进行更新.这对于获取新属性或其他联机映射更改很有用.以 ...

  7. elasticsearch6.7 05. Document APIs(4)Delete API

    3.Delete API delete API 可以让你删除一个特定id的文档,下面例子删除twitter索引中_doc类型.id为1的文档: DELETE /twitter/_doc/1 返回结果: ...

  8. elasticsearch6.7 05. Document APIs(3)GET API

    2.GET API get API 可以通过文档id从索引中获取json格式的文档,以下示例从twitter索引中获取type为_doc,id值为0为的JSON文档: GET twitter/_doc ...

  9. elasticsearch6.7 05. Document APIs(1)data replication model

    data replication model 本节首先简要介绍Elasticsearch的data replication model,然后详细描述以下CRUD api: 1.读写文档(Reading ...

随机推荐

  1. shell脚本学习-printf命令

    跟着RUNOOB网站的教程学习的笔记 printf命令模仿C程序库里的printf()程序.printf由POSIX标准所定义,因此使用printf的脚本比使用echo有着更好的移植性. printf ...

  2. Ubuntu 14.04 LTS 下使用源码编译安装 Sagemath 6.7 x64 (小结)

    原先博客放弃使用,几篇文章搬运过来 下载源码包 系统的最低要求: 6GB 硬盘 : 2GB RAM. 命令行工具: A C/C++ compiler: Since Sage builds its ow ...

  3. 05-使用jQuery操作input的value值

    表单控件是我们的重中之重,因为一旦牵扯到数据交互,离不开form表单的使用,比如用户的注册登录功能等 那么通过上节知识点我们了解到,我们在使用jquery方法操作表单控件的方法: $(selector ...

  4. Jetbrain Pycharm Theme

    https://github.com/ChrisRM/material-theme-jetbrains

  5. Anton 上课题

    Anton 上课题 Anton likes to play chess. Also he likes to do programming. No wonder that he decided to a ...

  6. MFC 多窗口通信时,使用RadioButton和Button时冲突问题

    最近项目需要我们实现在两个窗口间进行通信,其中有个小功能如图所示: 当我点击GDIProgram中的Button1时,会更新Dialog的Radio1和Radio2的状态. Dialog中的Radio ...

  7. iostat 命令详解

    前言 话说搞运维的人没有两把"刷子",都不好意思上服务器操作.还好,我还不是搞运维的,我一直都自诩是开发人员,奈何现在的东家运维人员"水"的一比,还要我这个自诩 ...

  8. WebService接口定义及调用

    Web service是一个平台独立的,松耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布式的互操作的应用程序. WebS ...

  9. 前置知识: FactoryBean的作用

    FactoryBean 简介 FactoryBean是Spring中一种特殊的Bean,是用于创建Bean对象的,最大的作用便是可以让我们自定义Bean的创建过程.如果你在XML配置文件配置了一个节点 ...

  10. JavaScript使用注意事项

    1.jQuery和JS中页面加载完后执行方法的写法 (1)在javascript中用来执行页面加载中的操作时候,我们会使用 window.onload=function(){} window.onlo ...