Elasticsearch的javaAPI之get,delete,bulk
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仍然异步)。 默认情况下,
被设置为
operationThreadedtrue
,
这意味着操作是由不同的线程上运行以下是一个演示样例,设置为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仍然异步)。
默认情况下,
被设置为
operationThreadedtrue
,
这意味着操作是由不同的线程上运行以下是一个演示样例,设置为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翻译欠佳。希望不会对大家造成误导
最新文章
- CSS选择器中类和ID选择器的区别
- Android 某些配置记录
- The Factory pattern
- 从零开始学习Linux(ls命令)
- JeeWx 微信管家平台
- js—对象
- 无线Ad-hoc网络的关键技术之路由(转)
- ref - 按引用传递参数
- qt 实现钟表图标
- Remove Invalid Parentheses 解答
- mui开发app之cropper裁剪后上传头像的实现
- Spring Cloud Stream同一通道根据消息内容分发不同的消费逻辑
- Luogu P5283 / LOJ3048 【[十二省联考2019]异或粽子】
- 高斯消元处理无解|多解情况 poj1830
- Python-ccs高级选择器 盒模型
- Ubuntu命令行
- python: numpy--函数 shape用法
- python之路-python字符编码
- 2010年腾讯前端面试题学习(jquery,html,css部分)
- Redis set 数据类型
热门文章
- Drupal Form问题汇总
- HDUOJ-----I NEED A OFFER!
- Python的 numpy中 numpy.ravel() 和numpy.flatten()的区别和使用
- Extending and Embedding PHP
- 如何在cmd命令行中查看、修改、删除与添加环境变量,语法格式例子:set path;echo %APPDATA%
- Android应用的自动升级、更新模块的实现
- iOS - Contacts 通讯录
- Linux内核中锁机制之完成量、互斥量
- org.hibernate.MappingException: entity class not found hbm可以解析,但是实体类不能解析
- Mongodb 与 Mongoose 的使用