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

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

最新文章

  1. CSS选择器中类和ID选择器的区别
  2. Android 某些配置记录
  3. The Factory pattern
  4. 从零开始学习Linux(ls命令)
  5. JeeWx 微信管家平台
  6. js—对象
  7. 无线Ad-hoc网络的关键技术之路由(转)
  8. ref - 按引用传递参数
  9. qt 实现钟表图标
  10. Remove Invalid Parentheses 解答
  11. mui开发app之cropper裁剪后上传头像的实现
  12. Spring Cloud Stream同一通道根据消息内容分发不同的消费逻辑
  13. Luogu P5283 / LOJ3048 【[十二省联考2019]异或粽子】
  14. 高斯消元处理无解|多解情况 poj1830
  15. Python-ccs高级选择器 盒模型
  16. Ubuntu命令行
  17. python: numpy--函数 shape用法
  18. python之路-python字符编码
  19. 2010年腾讯前端面试题学习(jquery,html,css部分)
  20. Redis set 数据类型

热门文章

  1. Drupal Form问题汇总
  2. HDUOJ-----I NEED A OFFER!
  3. Python的 numpy中 numpy.ravel() 和numpy.flatten()的区别和使用
  4. Extending and Embedding PHP
  5. 如何在cmd命令行中查看、修改、删除与添加环境变量,语法格式例子:set path;echo %APPDATA%
  6. Android应用的自动升级、更新模块的实现
  7. iOS - Contacts 通讯录
  8. Linux内核中锁机制之完成量、互斥量
  9. org.hibernate.MappingException: entity class not found hbm可以解析,但是实体类不能解析
  10. Mongodb 与 Mongoose 的使用