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. 网站博客更换主机空间搬家:Discuz! X2.5老鹰主机搬家全过程

    http://www.freehao123.com/discuz-x2-5-banjia/由于我放在hawkhost老鹰主机主机的部落论坛就要到期了,而老鹰主机的续费价格却是按照原价来的,没有任何优惠 ...

  2. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. android中完全退出当前应用程序的四种方法

    Android程序有很多Activity,比如说主窗口A,调用了子窗口B,如果在B中直接finish(), 接下里显示的是A.在B中如何关闭整个Android应用程序呢?本人总结了几种比较简单的实现方 ...

  4. Python学习笔记012——装饰器

    1 装饰器 1.1装饰器定义 在代码运行期间动态增加功能的方式,称之为“装饰器”(Decorator). 1.2 装饰器分类 装饰器:函数装饰器,类装饰器,函数的装饰器,类的装饰器 装饰器:函数装饰函 ...

  5. Linux时间子系统(一) 基本概念

    本文使用Q & A的方式来和大家以前探讨一下时间的基本概念 一.什么是时间? 这个问题实在是太复杂了,我都不知道这是一个物理学.宇宙学.还是热力学异或是哲学问题,我只是想从几个侧面来了解一下时 ...

  6. 【驱动笔记11】使用DeviceIoControl通信

    文章作者:grayfox作者主页:http://nokyo.blogbus.com原始出处:http://www.blogbus.com/nokyo-logs/34018521.html 在我昨日发布 ...

  7. win7 64 python2 xgboost安装

    综述: 首先,关于xgboost是啥,可以看这一篇:机器学习(四)--- 从gbdt到xgboost 安装Python3 环境下的xgboost 可以通过pip install , 在网址中下载对应版 ...

  8. 理解:Before和:After伪元素

    CSS样式表的主要作用是修饰Web页面上的HTML标记,但有时候,为了实现某个效果而往页面里反复添加某个HTML标记很繁琐,或者是显得多余,或者是由于某种原因而做不到.这就是CSS伪元素(Pseudo ...

  9. 利用PHPExcel实现数据保存到excel文件

    include(dirname(__FILE__) .'/phpexcel-1.7.7/Classes/PHPExcel.php'); include(dirname(__FILE__) .'/php ...

  10. spring cloud中通过配置文件自定义Ribbon负载均衡策略

    一.Ribbon中的负载均衡策略 1.Ribbon中支持的负载均衡策略 AvailabilityFilteringRule:过滤掉那些因为一直连接失败的被标记为circuit tripped的后端se ...