use of org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class Searches method scroll.
public ScrollResult scroll(String query, TimeRange range, int limit, int offset, List<String> fields, String filter) {
final Set<String> indices = determineAffectedIndices(range, filter);
// only request the fields we asked for otherwise we can't figure out which fields will be in the result set
// until we've scrolled through the entire set.
// TODO: Check if we can get away without loading the _source field.
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html#search-request-fields
// "For backwards compatibility, if the fields parameter specifies fields which are not stored , it will
// load the _source and extract it from it. This functionality has been replaced by the source filtering
// parameter." -- So we should look at the source filtering parameter once we switched to ES 1.x.
final SearchRequest request = standardSearchRequest(query, indices, limit, offset, range, filter, null, false).setScroll(new TimeValue(1, TimeUnit.MINUTES)).setSize(// TODO magic numbers
500).addSort(SortBuilders.fieldSort(SortParseElement.DOC_FIELD_NAME)).addFields(fields.toArray(new String[fields.size()])).addField(// always request the _source field because otherwise we can't access non-stored values
"_source").request();
if (LOG.isDebugEnabled()) {
try {
LOG.debug("ElasticSearch scroll query: {}", XContentHelper.convertToJson(request.source(), false));
} catch (IOException ignored) {
}
}
final SearchResponse r = c.search(request).actionGet();
recordEsMetrics(r, range);
return new ScrollResult(c, query, request.source(), r, fields);
}
use of org.elasticsearch.action.search.SearchRequest in project metron by apache.
the class ElasticsearchRequestSubmitterTest method searchShouldHandleShardFailure.
@Test
public void searchShouldHandleShardFailure() throws InvalidSearchException {
// mocks
SearchResponse response = mock(SearchResponse.class);
SearchRequest request = new SearchRequest();
ShardSearchFailure fail = mock(ShardSearchFailure.class);
SearchShardTarget target = new SearchShardTarget("node1", mock(Index.class), 1, "metron");
// response will have status of OK
when(response.status()).thenReturn(RestStatus.OK);
// the response will report shard failures
when(response.getFailedShards()).thenReturn(1);
when(response.getTotalShards()).thenReturn(2);
// the response will return the failures
ShardSearchFailure[] failures = { fail };
when(response.getShardFailures()).thenReturn(failures);
// shard failure needs to report the node
when(fail.shard()).thenReturn(target);
// shard failure needs to report details of failure
when(fail.index()).thenReturn("bro_index_2017-10-11");
when(fail.shardId()).thenReturn(1);
// search should succeed, even with failed shards
ElasticsearchRequestSubmitter submitter = setup(response);
SearchResponse actual = submitter.submitSearch(request);
assertNotNull(actual);
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class AbstractBulkByScrollRequest method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
searchRequest = new SearchRequest();
searchRequest.readFrom(in);
abortOnVersionConflict = in.readBoolean();
size = in.readVInt();
refresh = in.readBoolean();
timeout = new TimeValue(in);
activeShardCount = ActiveShardCount.readFrom(in);
retryBackoffInitialTime = new TimeValue(in);
maxRetries = in.readVInt();
requestsPerSecond = in.readFloat();
if (in.getVersion().onOrAfter(Version.V_5_1_1_UNRELEASED)) {
slices = in.readVInt();
} else {
slices = 1;
}
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class BulkByScrollParallelizationHelper method startSlices.
public static <Request extends AbstractBulkByScrollRequest<Request>> void startSlices(Client client, TaskManager taskManager, Action<Request, BulkByScrollResponse, ?> action, String localNodeId, ParentBulkByScrollTask task, Request request, ActionListener<BulkByScrollResponse> listener) {
TaskId parentTaskId = new TaskId(localNodeId, task.getId());
for (final SearchRequest slice : sliceIntoSubRequests(request.getSearchRequest(), UidFieldMapper.NAME, request.getSlices())) {
// TODO move the request to the correct node. maybe here or somehow do it as part of startup for reindex in general....
Request requestForSlice = request.forSlice(parentTaskId, slice);
ActionListener<BulkByScrollResponse> sliceListener = ActionListener.wrap(r -> task.onSliceResponse(listener, slice.source().slice().getId(), r), e -> task.onSliceFailure(listener, slice.source().slice().getId(), e));
client.execute(action, requestForSlice, sliceListener);
}
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class AsyncBulkByScrollActionTests method setupForTest.
@Before
public void setupForTest() {
// Fill the context with something random so we can make sure we inherited it appropriately.
expectedHeaders.clear();
expectedHeaders.put(randomSimpleString(random()), randomSimpleString(random()));
setupClient(new TestThreadPool(getTestName()));
firstSearchRequest = new SearchRequest();
testRequest = new DummyAbstractBulkByScrollRequest(firstSearchRequest);
listener = new PlainActionFuture<>();
scrollId = null;
taskManager = new TaskManager(Settings.EMPTY);
testTask = (WorkingBulkByScrollTask) taskManager.register("don'tcare", "hereeither", testRequest);
localNode = new DiscoveryNode("thenode", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
taskId = new TaskId(localNode.getId(), testTask.getId());
}
Aggregations