Elsasticsearch的javaAPI之get

get API同意依据其id获得指定index中的基于json document。以下的样例得到一个JSON document(index为twitter,type为tweet,id为价值1)

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .execute()
        .actionGet();

在get操作的很多其它信息,能够查看REST get docs

线程操作

Get API同意你设置线程来运行操作。这样实际将运行API上运行的是同样的节点(API上运行一个分配在同一server的shard上)。

选择一个不同的线程上运行操作,或调用线程上运行它(注意,API仍然异步)。 默认情况下,
operationThreaded
 被设置为true这意味着操作是由不同的线程上运行以下是一个演示样例,设置为false:

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .execute()
        .actionGet();

Elsasticsearch的javaAPI之delete

delete API同意依据其id删除指定index中的json document。以下的样例:删除一个JSON document(index为twitter,type为tweet,id为价值1)

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1")
        .execute()
        .actionGet();

在删除操作的很多其它信息,查看delete API docs。

线程操作

Delete API同意你设置线程来运行操作。这样实际姜运行API上运行的是同样的节点(API上运行一个分配在同一server的shard上)。

选择一个不同的线程上运行操作,或调用线程上运行它(注意,API仍然异步)。

默认情况下,
operationThreaded
 被设置为true这意味着操作是由不同的线程上运行以下是一个演示样例,设置为false:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .execute()
        .actionGet();

Elasticsearch的javaAPI之bulk

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

}



原文http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/get.html

    http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/delete.html

    http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/bulk.html

翻译欠佳。希望不会对大家造成误导

Elasticsearch的javaAPI之get,delete,bulk的更多相关文章

  1. ElasticSearch的javaAPI之Client

    翻译的原文:http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html#node-c ...

  2. Elasticsearch的javaAPI之percolator

    Elasticsearch的javaAPI之percolator percolator同意一个在index中注冊queries,然后发送包括doc的请求,返回得到在index中注冊过的而且匹配doc的 ...

  3. elasticsearch的javaAPI之query

    elasticsearch的javaAPI之query API the Search API同意运行一个搜索查询,返回一个与查询匹配的结果(hits). 它能够在跨一个或多个index上运行, 或者一 ...

  4. Elasticsearch的javaAPI之query dsl-queries

    Elasticsearch的javaAPI之query dsl-queries 和rest query dsl一样,elasticsearch提供了一个完整的Java query dsl. 查询建造者 ...

  5. elasticsearch的javaAPI之index

    Index API 原文:http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html ...

  6. ElasticSearch(十一)批量CURD bulk

    1.bulk语法 POST /_bulk { "delete": { "_index": "test_index", "_type ...

  7. Elasticsearch增删改查 之 —— Delete删除

    删除文档也算是常用的操作了...如果把Elasticsearch当做一款普通的数据库,那么删除操作自然就很常用了.如果仅仅是全文检索,可能就不会太常用到删除. Delete API 删除API,可以根 ...

  8. java操作elasticsearch实现批量添加数据(bulk)

    java操作elasticsearch实现批量添加主要使用了bulk 代码如下: //bulk批量操作(批量添加) @Test public void test7() throws IOExcepti ...

  9. Elasticsearch的JavaAPI

    获取客户端对象 public class App { private TransportClient client; //获取客户端对象 @Before public void getClinet() ...

随机推荐

  1. PLSQL常用配置

    峰回路转,此乃常客! 01.PL/SQL Developer记住登陆密码 为了工作方便希望PL/SQL Developer记住登录Oracle的用户名和密码: 设置方法: PL/SQL Develop ...

  2. js insertBefore

    <select id="city" size="4" style="width:50px"> <option id=&qu ...

  3. js replaceChild

    //父亲元素.replaceChild(新,旧) 1 <ul id="city"> <li id="bj">北京</li> ...

  4. MySQL JOIN操作报错问题小解

    1 问题描述 在调用一个MySQL存储过程的时候,有时候会出现下面的错误: Illigal mix of collations(gbk\_chinese\_ci, IMPLICIT) and (lat ...

  5. nginx error: upstream prematurely closed connection while reading response header from upstream

    本篇文章由:http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-h ...

  6. 面向对象程序设计(OOP设计模式)-结构型模式之装饰器模式的应用与实现

    课程名称:程序设计方法学 实验4:OOP设计模式-结构型模式的应用与实现 时间:2015年11月18日星期三,第3.4节 地点:理1#208 一.实验目的 加深对结构型设计模式的理解以及在开发中的实际 ...

  7. eclipse 无代码自动提示

    http://blog.csdn.net/wgw335363240/article/details/6235427eclipse 无代码提示,显示No Default Proposals,Conten ...

  8. editplus发布3.01 Build 446 Final版(附下载及中文版)

    http://www.cnblogs.com/JustinYoung/archive/2008/04/14/editplus-301.html没有什么好说的,我个人最喜欢的编辑器.除了windows和 ...

  9. Chrome浏览器桌面通知提示功能使用

    http://www.cnblogs.com/meteoric_cry/archive/2012/03/31/2426256.html

  10. linux下core dump

    1.前言 一直在从事linux下后台开发,经常与core文件打交道.还记得刚开始从事linux下开发时,程序突然崩溃了,也没有任何日志.我不知所措,同事叫我看看core,我却问什么是core,怎么看. ...