org.elasticsearch.action.search.ClearScrollRequest Java Examples

The following examples show how to use org.elasticsearch.action.search.ClearScrollRequest. 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 vote down vote up
/**
     * 处理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 vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String scrollIds = request.param("scroll_id");
    ClearScrollRequest clearRequest = new ClearScrollRequest();
    clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
    if (RestActions.hasBodyContent(request)) {
        XContentType type = RestActions.guessBodyContentType(request);
       if (type == null) {
           scrollIds = RestActions.getRestContent(request).toUtf8();
           clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
       } else {
           // NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value
           clearRequest.setScrollIds(null);
           buildFromContent(RestActions.getRestContent(request), clearRequest);
       }
    }

    client.clearScroll(clearRequest, new RestStatusToXContentListener<ClearScrollResponse>(channel));
}
 
Example #3
Source File: RestClearScrollAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: ElasticsearchClient.java    From presto with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: SearchServiceTransportAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void sendFreeContext(DiscoveryNode node, long contextId, ClearScrollRequest request, final ActionListener<SearchFreeContextResponse> listener) {
    transportService.sendRequest(node, FREE_CONTEXT_SCROLL_ACTION_NAME, new ScrollFreeContextRequest(request, contextId), new ActionListenerResponseHandler<SearchFreeContextResponse>(listener) {
        @Override
        public SearchFreeContextResponse newInstance() {
            return new SearchFreeContextResponse();
        }
    });
}
 
Example #6
Source File: SearchServiceTransportAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void sendClearAllScrollContexts(DiscoveryNode node, ClearScrollRequest request, final ActionListener<TransportResponse> listener) {
    transportService.sendRequest(node, CLEAR_SCROLL_CONTEXTS_ACTION_NAME, new ClearScrollContextsRequest(request), new ActionListenerResponseHandler<TransportResponse>(listener) {
        @Override
        public TransportResponse newInstance() {
            return TransportResponse.Empty.INSTANCE;
        }
    });
}
 
Example #7
Source File: ElasticsearchIndexer.java    From datashare with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void clearScroll() throws IOException {
    ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
    clearScrollRequest.addScrollId(scrollId);
    this.client.clearScroll(clearScrollRequest);
    scrollId = null;
    totalHits = 0;
}
 
Example #8
Source File: SearchQueryServiceImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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 #9
Source File: TransportConnection.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
@NotNull
public ActionFuture<ClearScrollResponse> clearSearchScroll(@NotNull String scrollId) {
    ClearScrollRequest request = new ClearScrollRequest();
    request.addScrollId(scrollId);
    return client.clearScroll(request);
}
 
Example #10
Source File: ScrolledSearch.java    From james-project with Apache License 2.0 5 votes vote down vote up
public void close(AtomicReference<Optional<String>> scrollId) {
    scrollId.get().map(id -> {
            ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
            clearScrollRequest.addScrollId(id);
            return clearScrollRequest;
        }).ifPresent(Throwing.<ClearScrollRequest>consumer(clearScrollRequest -> client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT).subscribe()).sneakyThrow());
}
 
Example #11
Source File: SearchServiceTransportAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
ScrollFreeContextRequest(ClearScrollRequest request, long id) {
    this((TransportRequest) request, id);
}
 
Example #12
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public ActionFuture<ClearScrollResponse> clearScroll(ClearScrollRequest request) {
	return wrapped.clearScroll(request);
}
 
Example #13
Source File: ClientWithStats.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void clearScroll(ClearScrollRequest request, ActionListener<ClearScrollResponse> listener) {
	wrapped.clearScroll(request, listener);
}
 
Example #14
Source File: ReactorElasticSearchClient.java    From james-project with Apache License 2.0 4 votes vote down vote up
public Mono<ClearScrollResponse> clearScroll(ClearScrollRequest clearScrollRequest, RequestOptions options) {
    return toReactor(listener -> client.clearScrollAsync(clearScrollRequest, options, listener));
}
 
Example #15
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ClearScrollResponse> clearScroll(final ClearScrollRequest request) {
    return client.clearScroll(request);
}
 
Example #16
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
@Override
public void clearScroll(final ClearScrollRequest request, final ActionListener<ClearScrollResponse> listener) {
    client.clearScroll(request, listener);
}