Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 56e39dc

Browse files
author
admin
committed
优化文档
1 parent b8857be commit 56e39dc

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

‎document-apis/bulk-api.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
### Bulk API
3-
Bulk API可以批量插入:
43

4+
Bulk API,批量插入:
55

66
```
77
import static org.elasticsearch.common.xcontent.XContentFactory.*;
8+
```
89

10+
```
911
BulkRequestBuilder bulkRequest = client.prepareBulk();
1012
1113
// either use client#prepare, or use Requests# to directly build index/delete requests
@@ -32,5 +34,6 @@ bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
3234
BulkResponse bulkResponse = bulkRequest.get();
3335
if (bulkResponse.hasFailures()) {
3436
// process failures by iterating through each bulk response item
37+
//处理失败
3538
}
3639
```

‎document-apis/using-bulk-processor.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import org.elasticsearch.action.bulk.BulkProcessor;
1212
import org.elasticsearch.common.unit.ByteSizeUnit;
1313
import org.elasticsearch.common.unit.ByteSizeValue;
1414
import org.elasticsearch.common.unit.TimeValue;
15+
```
1516

17+
```
1618
BulkProcessor bulkProcessor = BulkProcessor.builder(
1719
client, //增加elasticsearch客户端
1820
new BulkProcessor.Listener() {
@@ -66,9 +68,9 @@ bulkProcessor.close();
6668
6769
```
6870

69-
#### 在测试用使用Bulk Processor
71+
#### 在测试中使用Bulk Processor
7072

71-
可以执行同步方法
73+
如果你在测试种使用`Bulk Processor`可以执行同步方法
7274
```
7375
BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() { /* Listener methods */ })
7476
.setBulkActions(10000)

‎search-api.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
搜索API可以支持搜索查询,返回查询匹配的结果,它可以搜索一个index / type 或者多个index / type,可以使用 [query Java API](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-query-dsl.html) 作为查询条件,下面是例子:
1+
# 搜索API
2+
3+
搜索查询,返回查询匹配的结果,搜索一个index / type 或者多个index / type,可以使用 [query Java API](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-query-dsl.html) 作为查询条件,下面是例子:
24

35

46
```
@@ -17,7 +19,7 @@ SearchResponse response = client.prepareSearch("index1", "index2")
1719
.get();
1820
```
1921

20-
所有的参数都是可选的,下面是最小调用:
22+
所有的参数都是可选的,下面是最简单的调用:
2123

2224

2325
```

‎search-api/multisearch-api.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ for (MultiSearchResponse.Item item : sr.getResponses()) {
2626

2727
#### 实例
2828

29+
- [MultiSearchAPI.java](https://gitee.com/quanke/elasticsearch-java-study/blob/master/src/test/java/name/quanke/es/study/search/MultiSearchAPI.java)
2930

30-
```
31-
32-
```
31+
- [本手册完整实例](https://gitee.com/quanke/elasticsearch-java-study)

‎search-api/search-template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
首先查看 [Search Template](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-template.html) 文档
77

8-
> /_search/template endpoint 允许我们在执行搜索请求和使用模板参数填充现有模板之前,能够使用 mustache 语言预先呈现搜索请求。
8+
> /_search/template endpoint 允许我们在执行搜索请求和使用模板参数填充现有模板之前,能够使用 `mustache` 语言预先呈现搜索请求。
99
1010
将模板参数定义为 `Map <String,Object>`:
1111

‎search-api/using-scrolls-in-java.md‎

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
Scroll API的创建并不是为了实时的用户响应,而是为了处理大量的数据(Scrolling is not intended for real time user requests, but rather for processing large amounts of data)。从 scroll 请求返回的结果只是反映了 search 发生那一时刻的索引状态,就像一个快照(The results that are returned from a scroll request reflect the state of the index at the time that the initial search request was made, like a snapshot in time)。后续的对文档的改动(索引、更新或者删除)都只会影响后面的搜索请求。
88

99

10-
11-
1210
```
1311
import static org.elasticsearch.index.query.QueryBuilders.*;
12+
```
1413

14+
```
1515
QueryBuilder qb = termQuery("multi", "test");
1616
1717
SearchResponse scrollResp = client.prepareSearch(test)
@@ -48,6 +48,7 @@ Caused by: SearchContextMissingException[No search context found for id [2861]]
4848
```
4949
> 虽然当滚动有效时间已过,搜索上下文(Search Context)会自动被清除,但是一值保持滚动代价也是很大的,所以当我们不在使用滚动时要尽快使用Clear-Scroll API进行清除。
5050
51+
## 清除Scroll
5152

5253
```
5354
/**
@@ -80,4 +81,49 @@ Caused by: SearchContextMissingException[No search context found for id [2861]]
8081

8182
```
8283
83-
```
84+
public class ScrollsAPI extends ElasticsearchClientBase {
85+
86+
private String scrollId;
87+
88+
@Test
89+
public void testScrolls() throws Exception {
90+
91+
SearchResponse scrollResp = client.prepareSearch("twitter")
92+
.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
93+
.setScroll(new TimeValue(60000)) //为了使用 scroll,初始搜索请求应该在查询中指定 scroll 参数,告诉 Elasticsearch 需要保持搜索的上下文环境多长时间(滚动时间)
94+
.setQuery(QueryBuilders.termQuery("user", "kimchy")) // Query 查询条件
95+
.setSize(5).get(); //max of 100 hits will be returned for each scroll
96+
//Scroll until no hits are returned
97+
98+
scrollId = scrollResp.getScrollId();
99+
do {
100+
for (SearchHit hit : scrollResp.getHits().getHits()) {
101+
//Handle the hit...
102+
103+
System.out.println("" + hit.getSource().toString());
104+
}
105+
106+
scrollResp = client.prepareSearchScroll(scrollId).setScroll(new TimeValue(60000)).execute().actionGet();
107+
}
108+
while (scrollResp.getHits().getHits().length != 0); // Zero hits mark the end of the scroll and the while loop.
109+
}
110+
111+
@Override
112+
public void tearDown() throws Exception {
113+
ClearScrollRequestBuilder clearScrollRequestBuilder = client.prepareClearScroll();
114+
clearScrollRequestBuilder.addScrollId(scrollId);
115+
ClearScrollResponse response = clearScrollRequestBuilder.get();
116+
117+
if (response.isSucceeded()) {
118+
System.out.println("成功清除");
119+
}
120+
121+
super.tearDown();
122+
}
123+
}
124+
125+
```
126+
127+
- [ScrollsAPI.java](https://gitee.com/quanke/elasticsearch-java-study/blob/master/src/test/java/name/quanke/es/study/search/ScrollsAPI.java)
128+
129+
- [本手册完整实例](https://gitee.com/quanke/elasticsearch-java-study)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /