Java Code Examples for org.elasticsearch.action.search.ClearScrollRequest#addScrollId()
The following examples show how to use
org.elasticsearch.action.search.ClearScrollRequest#addScrollId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchUtil.java From SpringBootLearn with Apache License 2.0 | 6 votes |
/** * 处理scroll结果 * @Author lihaodong * @Description * @Date 20:18 2018/12/21 * @Param [response, highlightField] * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>> **/ private static List<Map<String, Object>> disposeScrollResult(SearchResponse response ,String highlightField){ List<Map<String, Object>> sourceList = new ArrayList<Map<String, Object>>(); //使用scrollId迭代查询 while (response.getHits().getHits().length > 0) { String scrollId = response.getScrollId(); response = client.prepareSearchScroll(scrollId) .setScroll(TimeValue.timeValueMinutes(1))//设置查询context的存活时间 .execute() .actionGet(); SearchHits hits = response.getHits(); for (SearchHit hit : hits.getHits()) { Map<String, Object> resultMap =getResultMap(hit, highlightField); sourceList.add(resultMap); // System.out.println(JSON.toJSONString(resultMap)); } } ClearScrollRequest request = new ClearScrollRequest(); request.addScrollId(response.getScrollId()); client.clearScroll(request); return sourceList; }
Example 2
Source File: RestClearScrollAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static void buildFromContent(BytesReference content, ClearScrollRequest clearScrollRequest) { try (XContentParser parser = XContentHelper.createParser(content)) { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("Malformed content, must start with an object"); } else { XContentParser.Token token; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if ("scroll_id".equals(currentFieldName) && token == XContentParser.Token.START_ARRAY) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token.isValue() == false) { throw new IllegalArgumentException("scroll_id array element should only contain scroll_id"); } clearScrollRequest.addScrollId(parser.text()); } } else { throw new IllegalArgumentException("Unknown parameter [" + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] "); } } } } catch (IOException e) { throw new IllegalArgumentException("Failed to parse request body", e); } }
Example 3
Source File: ElasticsearchClient.java From presto with Apache License 2.0 | 5 votes |
public void clearScroll(String scrollId) { ClearScrollRequest request = new ClearScrollRequest(); request.addScrollId(scrollId); try { client.clearScroll(request); } catch (IOException e) { throw new PrestoException(ELASTICSEARCH_CONNECTION_ERROR, e); } }
Example 4
Source File: ElasticsearchIndexer.java From datashare with GNU Affero General Public License v3.0 | 5 votes |
@Override public void clearScroll() throws IOException { ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); clearScrollRequest.addScrollId(scrollId); this.client.clearScroll(clearScrollRequest); scrollId = null; totalHits = 0; }
Example 5
Source File: SearchQueryServiceImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void closeScrollId() { log.debug("Clearing scroll id {}", response.getScrollId()); ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); clearScrollRequest.addScrollId(response.getScrollId()); ClearScrollResponse clearScrollResponse = client.get().clearScroll(clearScrollRequest).actionGet(); if (!clearScrollResponse.isSucceeded()) { log.info("Unable to close scroll id {}", response.getScrollId()); } }
Example 6
Source File: TransportConnection.java From heroic with Apache License 2.0 | 5 votes |
@Override @NotNull public ActionFuture<ClearScrollResponse> clearSearchScroll(@NotNull String scrollId) { ClearScrollRequest request = new ClearScrollRequest(); request.addScrollId(scrollId); return client.clearScroll(request); }