elasticsearch 中文API bulk(六)

bulk API

bulk API允许开发者在一个请求中索引和删除多个文档。下面是使用实例。

import static org.elasticsearch.common.xcontent.XContentFactory.*;

BulkRequestBuilder bulkRequest = client.prepareBulk();

// either use client#prepare, or use Requests# to directly build index/delete requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "trying out Elasticsearch")
                    .endObject()
                  )
        );

bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "another post")
                    .endObject()
                  )
        );

BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
    // process failures by iterating through each bulk response item
}
时间: 2024-08-14 04:23:51

elasticsearch 中文API bulk(六)的相关文章

elasticsearch 中文API 搜索(六)

搜索API 搜索API允许开发者执行一个搜索查询,返回满足查询条件的搜索信息.它能够跨索引以及跨类型执行.查询既可以用Java查询API也可以用Java过滤API. 查询的请求体由SearchSourceBuilder构建. import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.

elasticsearch 中文API(一)

Java API 这节会介绍elasticsearch支持的Java API.所有的elasticsearch操作都使用Client对象执行.本质上,所有的操作都是并行执行的. 另外,Client中的操作有可能累积并通过Bulk执行. maven Elasticsearch托管在Maven仓库中.例如,你可以在pom.xml中定义最新的版本. <dependency> <groupId>org.elasticsearch</groupId> <artifactId

elasticsearch 中文API river

river-jdbc 安装 ./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.4.0.8/elasticsearch-river-jdbc-1.4.0.8-plugin.zip 文档 两种方式:river或者feeder 该插件能够以“pull模式”执行river和以“push模式”执行feeder.在feede

elasticsearch 中文API facets(⑩)

facets Elasticsearch提供完整的java API用来支持facets.在查询的过程中,将需要计数的facets添加到FacetBuilders中.然后将该FacetBuilders条件到查询请求中. SearchResponse sr = node.client().prepareSearch() .setQuery( /* your query */ ) .addFacet( /* add a facet */ ) .execute().actionGet(); 为了构建fa

elasticsearch 中文API 索引(三)

索引API 索引API允许开发者索引类型化的JSON文档到一个特定的索引,使其可以被搜索. 生成JSON文档 有几种不同的方式生成JSON文档 利用byte[]或者作为一个String手动生成 利用一个Map将其自动转换为相应的JSON 利用第三方库如Jackson去序列化你的bean 利用内置的帮助函数XContentFactory.jsonBuilder() 手动生成 需要注意的是,要通过Date Format编码日期. String json = "{" + "\&qu

elasticsearch 中文API 记数(八)

计数API 计数API允许开发者简单的执行一个查询,返回和查询条件相匹配的文档的总数.它可以跨多个索引以及跨多个类型执行. import static org.elasticsearch.index.query.xcontent.FilterBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; CountResponse response = client.prepareCount("t

elasticsearch 中文API 基于查询的删除(九)

基于查询的删除API 基于查询的删除API允许开发者基于查询删除一个或者多个索引.一个或者多个类型.下面是一个例子. import static org.elasticsearch.index.query.FilterBuilders.*; import static org.elasticsearch.index.query.QueryBuilders.*; DeleteByQueryResponse response = client.prepareDeleteByQuery("test&q

elasticsearch 中文API 获得(三)

获取API 获取API允许你通过id从索引中获取类型化的JSON文档,如下例: GetResponse response = client.prepareGet("twitter", "tweet", "1") .execute() .actionGet(); 操作线程 The get API allows to set the threading model the operation will be performed when the ac

elasticsearch 中文API(二)

客户端 有多个地方需要使用Java client: 在存在的集群中执行标准的index, get, delete和search 在集群中执行管理任务 当你要运行嵌套在你的应用程序中的Elasticsearch的时候或者当你要运行单元测试或者集合测试的时候,启动所有节点 获得一个Client是非常容易的,最通用的步骤如下所示: 创建一个嵌套的节点,充当集群的一个节点 从这个嵌套的节点请求一个Client 另外一种方式是创建一个TransportClient来连接集群. 重要提示: 客户端和集群端推