ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 企业开发 >> Elasticsearch 220 文档篇:多文档操作

Elasticsearch 220 文档篇:多文档操作(3/3)

来源:网络整理     时间:2016-02-12     关键词:

本篇文章主要介绍了"Elasticsearch 220 文档篇:多文档操作",主要涉及到方面的内容,对于企业开发感兴趣的同学可以参考一下: 在Elasticsearch对文档的操作中,之前介绍的都是对单个文档进行操作,其实Elasticsearch同时可以对多个文档同时操作。下面介绍多文档查...

{
  "docs" : [ {
    "_index" : "secilog",
    "_type" : "log",
    "_id" : "1",
    "_version" : 3,
    "found" : true
  }, {
    "_index" : "secilog",
    "_type" : "log",
    "_id" : "2",
    "_version" : 1,
    "found" : true,
    "_source" : {
      "collect_date" : "2016-01-12T09:32:12",
      "collect_type" : "syslog"
    }
  } ]
}

类似单个文档查询,在请求的url中或者参数的docs中可以指定field,routing参数。

块操作

    快操作可以在一个接口中,处理个文档的内容,包括创建文档,删除文档,和修改文档。用块操作方式操作多个文档可以提高系统的效率。例如:

请求:POST http://localhost:9200/_bulk?pretty

参数:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "10" } }
{ "field1" : "value1" }
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "13" } }
{ "field1" : "value3" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "12" } }
}

返回结果:

{
  "took" : 1,
  "errors" : false,
  "items" : [ {
    "index" : {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "10",
      "_version" : 6,
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "status" : 200
    }
  }, {
    "index" : {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "13",
      "_version" : 1,
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "status" : 201
    }
  }, {
    "delete" : {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "12",
      "_version" : 2,
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "status" : 404,
      "found" : false
    }
  } ]
}

    和批量查询类似, /_bulk, /{index}/_bulk, and {index}/{type}/_bulk这三种方式都可以执行,只需要在请求的参数中做出相应的对应。

 赛克蓝德(secisland)后续会逐步对Elasticsearch的最新版本的各项功能进行分析,近请期待。也欢迎加入secisland公众号进行关注

以上就介绍了Elasticsearch 220 文档篇:多文档操作,包括了方面的内容,希望对企业开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_319956_3.html

相关图片

相关文章