org.elasticsearch.action.search.SearchRequest Java Examples
The following examples show how to use
org.elasticsearch.action.search.SearchRequest.
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: ESClient.java From dht-spider with MIT License | 10 votes |
public List<MetaData> search(String searchValue) throws Exception{ List<MetaData> list=new ArrayList<>(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.from(0); searchSourceBuilder.size(100); searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS)); searchSourceBuilder.query(QueryBuilders.matchQuery("name", searchValue)); SearchRequest searchRequest = new SearchRequest(); searchRequest.indices("torrent"); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); SearchHits hits = searchResponse.getHits(); SearchHit[] searchHits = hits.getHits(); for (SearchHit hit : searchHits) { Map<String, Object> sourceAsMap = hit.getSourceAsMap(); list.add(new MetaData((String)sourceAsMap.get("infoHash"), Long.parseLong(String.valueOf(sourceAsMap.get("length"))), (String)sourceAsMap.get("name"),(String)sourceAsMap.get("nameInfo"))); } return list; }
Example #2
Source File: TestSchema.java From kafka-connect-elasticsearch-source with Apache License 2.0 | 6 votes |
public void testSearch() throws Exception { SearchRequest searchRequest = new SearchRequest(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchAllQuery()); searchRequest.source(searchSourceBuilder); searchRequest.indices("metricbeat-6.2.4-2018.05.20"); SearchResponse searchResponse = es.getClient().search(searchRequest); SearchHits hits = searchResponse.getHits(); SearchHit[] searchHits = hits.getHits(); for (SearchHit hit : searchHits) { // do something with the SearchHit Map<String, Object> sourceAsMap = hit.getSourceAsMap(); System.out.println(sourceAsMap); Schema schema = SchemaConverter.convertElasticMapping2AvroSchema(sourceAsMap, "test"); schema.toString(); Struct struct = StructConverter.convertElasticDocument2AvroStruct(sourceAsMap,schema); struct.toString(); } }
Example #3
Source File: ESReporterTest.java From james-project with Apache License 2.0 | 6 votes |
private boolean checkMetricRecordedInElasticSearch() { try (ReactorElasticSearchClient client = elasticSearchExtension.getDockerES().clientProvider().get()) { SearchRequest searchRequest = new SearchRequest() .source(new SearchSourceBuilder() .query(QueryBuilders.matchAllQuery())); return !Arrays.stream(client .search(searchRequest) .block() .getHits() .getHits()) .filter(searchHit -> searchHit.getIndex().startsWith(TestDockerESMetricReporterModule.METRICS_INDEX)) .collect(Collectors.toList()) .isEmpty(); } catch (Exception e) { return false; } }
Example #4
Source File: AuditlogTest.java From deprecated-security-advanced-modules with Apache License 2.0 | 6 votes |
@Test public void testSearchRequest() { SearchRequest sr = new SearchRequest(); sr.indices("index1","logstash*"); sr.types("mytype","logs"); Settings settings = Settings.builder() .put("opendistro_security.audit.type", TestAuditlogImpl.class.getName()) .put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_TRANSPORT_CATEGORIES, "NONE") .put("opendistro_security.audit.threadpool.size", 0) .build(); AbstractAuditLog al = new AuditLogImpl(settings, null, null, AbstractSecurityUnitTest.MOCK_POOL, null, cs); TestAuditlogImpl.clear(); al.logGrantedPrivileges("indices:data/read/search", sr, null); Assert.assertEquals(1, TestAuditlogImpl.messages.size()); }
Example #5
Source File: LegacyDetectorRepositoryImpl.java From adaptive-alerting with Apache License 2.0 | 6 votes |
private List<DetectorDocument> getDetectorsFromElasticSearch(SearchRequest searchRequest) { SearchResponse response; try { response = legacyElasticSearchClient.search(searchRequest, RequestOptions.DEFAULT); } catch (IOException e) { log.error("Error ES lookup", e); throw new RuntimeException(e); } SearchHit[] hits = response.getHits().getHits(); List<DetectorDocument> detectors = new ArrayList<>(); for (val hit : hits) { val detector = (DetectorDocument) objectMapperUtil.convertToObject(hit.getSourceAsString(), new TypeReference<DetectorDocument>() { }); val newElasticsearchDetector = getElasticSearchDetector(detector); detectors.add(newElasticsearchDetector); } return detectors; }
Example #6
Source File: ElasticSearchIndexerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void deleteMessage() { DocumentId documentId = DocumentId.fromString("1:2"); String content = "{\"message\": \"trying out Elasticsearch\"}"; testee.index(documentId, content, useDocumentId(documentId)).block(); elasticSearch.awaitForElasticSearch(); testee.delete(ImmutableList.of(documentId), useDocumentId(documentId)).block(); elasticSearch.awaitForElasticSearch(); SearchResponse searchResponse = client.search( new SearchRequest(INDEX_NAME.getValue()) .source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery())), RequestOptions.DEFAULT) .block(); assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(0); }
Example #7
Source File: CardinalityEstimationTask.java From siren-join with GNU Affero General Public License v3.0 | 6 votes |
protected void executeCardinalityRequest(final NodeTaskContext context, final NodeTaskReporter reporter) { logger.debug("Executing async cardinality action"); final SearchRequest cardinalityRequest = this.getCardinalityRequest(context.getNode(), context.getVisitor().getParentRequest()); context.getClient().execute(SearchAction.INSTANCE, cardinalityRequest, new ActionListener<SearchResponse>() { @Override public void onResponse(SearchResponse searchResponse) { Cardinality c = searchResponse.getAggregations().get(context.getNode().getLookupPath()); context.getNode().setCardinality(c.getValue()); reporter.success(context); } @Override public void onFailure(Throwable e) { reporter.failure(e); } }); }
Example #8
Source File: PercentilesAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ QueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("cmd", "weather_hourforcast"); PercentilesAggregationBuilder aggregationBuilder = AggregationBuilders.percentiles("utm").field("utm").keyed(false); // PercentilesAggregationBuilder aggregationBuilder = AggregationBuilders.percentiles("utm").field("utm").percentiles(95,99,99.9).keyed(false);//自定义百分区间 SearchRequest searchRequest = new SearchRequest("serverlog_20180710");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(matchQueryBuilder); searchSourceBuilder.aggregation(aggregationBuilder); searchSourceBuilder.size(0); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); }finally{ HighLevelClient.close(); } }
Example #9
Source File: MetricProfileRepositoryImpl.java From adaptive-alerting with Apache License 2.0 | 6 votes |
@Override public Boolean profilingExists(Map<String, String> tags) { try { List<BytesReference> refList = new ArrayList<>(); XContentBuilder xContent = XContentFactory.jsonBuilder(); xContent.map(tags); refList.add(BytesReference.bytes(xContent)); PercolateQueryBuilder percolateQuery = new PercolateQueryBuilder(PercolatorMetricProfiling.QUERY_KEYWORD, refList, XContentType.JSON); val boolQueryBuilder = new BoolQueryBuilder(); boolQueryBuilder.filter(percolateQuery); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(boolQueryBuilder); searchSourceBuilder.timeout(new TimeValue(elasticSearchProperties.getConfig().getConnectionTimeout())); searchSourceBuilder.size(500); val searchRequest = new SearchRequest().source(searchSourceBuilder).indices(METRIC_PROFILING_INDEX); val searchResponse = legacyElasticSearchClient.search(searchRequest, RequestOptions.DEFAULT); return searchResponse.getHits().getHits().length > 0; } catch (IOException e) { log.error("Error ES lookup", e); throw new RuntimeException(e); } }
Example #10
Source File: EsSearchRequestBuilder.java From occurrence with Apache License 2.0 | 6 votes |
static SearchRequest buildSuggestQuery( String prefix, OccurrenceSearchParameter parameter, Integer limit, String index) { SearchRequest request = new SearchRequest(); request.indices(index); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); request.source(searchSourceBuilder); OccurrenceEsField esField = SEARCH_TO_ES_MAPPING.get(parameter); // create suggest query searchSourceBuilder.suggest( new SuggestBuilder() .addSuggestion( esField.getFieldName(), SuggestBuilders.completionSuggestion(esField.getFieldName() + ".suggest") .prefix(prefix) .size(limit != null ? limit : SearchConstants.DEFAULT_SUGGEST_LIMIT) .skipDuplicates(true))); // add source field searchSourceBuilder.fetchSource(esField.getFieldName(), null); return request; }
Example #11
Source File: SearchableImpl.java From spring-content with Apache License 2.0 | 6 votes |
@Override public Iterable<Serializable> findKeyword(String query) { SearchRequest searchRequest = new SearchRequest(INDEX_NAME); searchRequest.types(domainClass.getName()); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(QueryBuilders.queryStringQuery(query)); searchRequest.source(sourceBuilder); SearchResponse res = null; try { res = client.search(searchRequest, RequestOptions.DEFAULT); } catch (IOException ioe) { throw new StoreAccessException(format("Error searching indexed content for '%s'", query), ioe); } return getIDs(res.getHits()); }
Example #12
Source File: AnomalyDetectorProfileRunner.java From anomaly-detection with Apache License 2.0 | 6 votes |
/** * We expect three kinds of states: * -Disabled: if get ad job api says the job is disabled; * -Init: if anomaly score after the last update time of the detector is larger than 0 * -Running: if neither of the above applies and no exceptions. * @param detectorId detector id * @param enabledTime the time when AD job is enabled in milliseconds * @param listener listener to process the returned state or exception * @param enabled whether the detector job is enabled or not */ private void profileState( String detectorId, long enabledTime, MultiResponsesDelegateActionListener<DetectorProfile> listener, boolean enabled ) { if (enabled) { SearchRequest searchLatestResult = createInittedEverRequest(detectorId, enabledTime); client.search(searchLatestResult, onInittedEver(listener, detectorId, enabledTime)); } else { DetectorProfile profile = new DetectorProfile(); profile.setState(DetectorState.DISABLED); listener.onResponse(profile); } }
Example #13
Source File: AnomalyDetectorProfileRunner.java From anomaly-detection with Apache License 2.0 | 6 votes |
/** * Create search request to check if we have at least 1 anomaly score larger than 0 after AD job enabled time * @param detectorId detector id * @param enabledTime the time when AD job is enabled in milliseconds * @return the search request */ private SearchRequest createInittedEverRequest(String detectorId, long enabledTime) { BoolQueryBuilder filterQuery = new BoolQueryBuilder(); filterQuery.filter(QueryBuilders.termQuery(AnomalyResult.DETECTOR_ID_FIELD, detectorId)); filterQuery.filter(QueryBuilders.rangeQuery(AnomalyResult.EXECUTION_END_TIME_FIELD).gte(enabledTime)); filterQuery.filter(QueryBuilders.rangeQuery(AnomalyResult.ANOMALY_SCORE_FIELD).gt(0)); // I am only looking for last 1 occurrence and have no interest in the total number of documents that match the query. // ES will not try to count the number of documents and will be able to terminate the query as soon as 1 document // have been collected per segment. SearchSourceBuilder source = new SearchSourceBuilder().query(filterQuery).size(1).trackTotalHits(false); SearchRequest request = new SearchRequest(AnomalyResult.ANOMALY_RESULT_INDEX); request.source(source); return request; }
Example #14
Source File: ClusteringAction.java From elasticsearch-carrot2 with Apache License 2.0 | 6 votes |
public ClusteringActionRequest(StreamInput in) throws IOException { SearchRequest searchRequest = new SearchRequest(in); this.searchRequest = searchRequest; this.queryHint = in.readOptionalString(); this.algorithm = in.readOptionalString(); this.maxHits = in.readInt(); this.createUngroupedDocumentsCluster = in.readBoolean(); this.defaultLanguage = in.readString(); int count = in.readVInt(); while (count-- > 0) { FieldMappingSpec spec = new FieldMappingSpec(in); fieldMapping.add(spec); } boolean hasAttributes = in.readBoolean(); if (hasAttributes) { attributes = in.readMap(); } }
Example #15
Source File: ElasticSearchRestDAOV6.java From conductor with Apache License 2.0 | 6 votes |
@Override public List<EventExecution> getEventExecutions(String event) { try { BoolQueryBuilder query = boolQueryBuilder("event='" + event + "'", "*"); // Create the searchObjectIdsViaExpression source SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(query); searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC)); // Generate the actual request to send to ES. String docType = StringUtils.isBlank(docTypeOverride) ? EVENT_DOC_TYPE : docTypeOverride; SearchRequest searchRequest = new SearchRequest(eventIndexPrefix + "*"); searchRequest.types(docType); searchRequest.source(searchSourceBuilder); SearchResponse response = elasticSearchClient.search(searchRequest); return mapEventExecutionsResponse(response); } catch (Exception e) { logger.error("Failed to get executions for event: {}", event, e); } return null; }
Example #16
Source File: SearchServiceTransportAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
public void sendFreeContext(DiscoveryNode node, final long contextId, SearchRequest request) { transportService.sendRequest(node, FREE_CONTEXT_ACTION_NAME, new SearchFreeContextRequest(request, contextId), new ActionListenerResponseHandler<SearchFreeContextResponse>(new ActionListener<SearchFreeContextResponse>() { @Override public void onResponse(SearchFreeContextResponse response) { // no need to respond if it was freed or not } @Override public void onFailure(Throwable e) { } }) { @Override public SearchFreeContextResponse newInstance() { return new SearchFreeContextResponse(); } }); }
Example #17
Source File: ADStateManagerTests.java From anomaly-detection with Apache License 2.0 | 6 votes |
public void testHasRunningQuery() throws IOException { stateManager = new ADStateManager( client, xContentRegistry(), modelManager, settings, new ClientUtil(settings, client, throttler, context), clock, duration ); AnomalyDetector detector = TestHelpers.randomAnomalyDetector(ImmutableMap.of(), null); SearchRequest dummySearchRequest = new SearchRequest(); assertFalse(stateManager.hasRunningQuery(detector)); throttler.insertFilteredQuery(detector.getDetectorId(), dummySearchRequest); assertTrue(stateManager.hasRunningQuery(detector)); }
Example #18
Source File: CountRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
public SearchRequest toSearchRequest() { SearchRequest searchRequest = new SearchRequest(indices()); searchRequest.indicesOptions(indicesOptions()); searchRequest.types(types()); searchRequest.routing(routing()); searchRequest.preference(preference()); searchRequest.source(source()); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.size(0); if (minScore() != DEFAULT_MIN_SCORE) { searchSourceBuilder.minScore(minScore()); } if (terminateAfter() != DEFAULT_TERMINATE_AFTER) { searchSourceBuilder.terminateAfter(terminateAfter()); } searchRequest.extraSource(searchSourceBuilder); return searchRequest; }
Example #19
Source File: ElasticsearchCatalogService.java From staccato with Apache License 2.0 | 6 votes |
/** * Searches for a collection of items given a api query built from path variables that were traversed in a * subcatalog. * @param collectionId The id of the collection * @param pathVariables A map of fieldnames and their corresponding values that should be used to build the api * query * @return The collection of item results wrapped in a Mono */ @Override public Mono<ItemCollection> getItems(String collectionId, Map<String, String> pathVariables) { StringBuilder sb = new StringBuilder(); Iterator<Map.Entry<String, String>> it = pathVariables.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); sb.append("properties." + entry.getKey() + "=" + entry.getValue()); if (it.hasNext()) { sb.append(" AND "); } } com.planet.staccato.dto.api.SearchRequest searchRequest = new com.planet.staccato.dto.api.SearchRequest(); String query = sb.toString().isBlank() ? null : sb.toString(); searchRequest.setQuery(query); searchRequest.setLimit(10); searchRequest.setCollections(new String[]{collectionId}); return searchService.getItemCollection(searchRequest); }
Example #20
Source File: ElasticSearchUtil.java From ranger with Apache License 2.0 | 6 votes |
public SearchResponse searchResources(SearchCriteria searchCriteria, List<SearchField> searchFields, List<SortField> sortFields, RestHighLevelClient client, String index) throws IOException { // See Also: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-query-builders.html QueryAccumulator queryAccumulator = new QueryAccumulator(searchCriteria); if (searchCriteria.getParamList() != null) { searchFields.stream().forEach(queryAccumulator::addQuery); // For now assuming there is only date field where range query will // be done. If we there are more than one, then we should create a // hashmap for each field name if (queryAccumulator.fromDate != null || queryAccumulator.toDate != null) { queryAccumulator.queries.add(setDateRange(queryAccumulator.dateFieldName, queryAccumulator.fromDate, queryAccumulator.toDate)); } } BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); queryAccumulator.queries.stream().filter(x -> x != null).forEach(boolQueryBuilder::must); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); setSortClause(searchCriteria, sortFields, searchSourceBuilder); searchSourceBuilder.from(searchCriteria.getStartIndex()); searchSourceBuilder.size(searchCriteria.getMaxRows()); searchSourceBuilder.fetchSource(true); SearchRequest query = new SearchRequest(); query.indices(index); query.source(searchSourceBuilder.query(boolQueryBuilder)); return client.search(query, RequestOptions.DEFAULT); }
Example #21
Source File: ElasticSearchQueryManualTest.java From tutorials with MIT License | 6 votes |
@Test public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags") .field("title"); final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); final SearchRequest searchRequest = new SearchRequest("blog").source(builder); final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); final Map<String, Aggregation> results = response.getAggregations() .asMap(); final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); final List<String> keys = topTags.getBuckets() .stream() .map(MultiBucketsAggregation.Bucket::getKeyAsString) .sorted() .collect(toList()); assertEquals(asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); }
Example #22
Source File: ElasticsearchSpewerTest.java From datashare with GNU Affero General Public License v3.0 | 6 votes |
@Test public void test_embedded_document() throws Exception { Path path = get(getClass().getResource("/docs/embedded_doc.eml").getPath()); final TikaDocument document = new Extractor().extract(path); spewer.write(document); GetResponse documentFields = es.client.get(new GetRequest(TEST_INDEX, "doc", document.getId())); assertTrue(documentFields.isExists()); SearchRequest searchRequest = new SearchRequest(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.multiMatchQuery("simple.tiff", "content")); searchRequest.source(searchSourceBuilder); SearchResponse response = es.client.search(searchRequest); assertThat(response.getHits().totalHits).isGreaterThan(0); //assertThat(response.getHits().getAt(0).getId()).endsWith("embedded.pdf"); verify(publisher, times(2)).publish(eq(Channel.NLP), any(Message.class)); }
Example #23
Source File: EsUtil.java From demo-project with MIT License | 6 votes |
/** * Description: 搜索 * * @param index index * @param builder 查询参数 * @param c 结果类对象 * @return java.util.ArrayList * @author fanxb * @date 2019/7/25 13:46 */ public <T> List<T> search(String index, SearchSourceBuilder builder, Class<T> c) { SearchRequest request = new SearchRequest(index); request.source(builder); try { SearchResponse response = client.search(request, RequestOptions.DEFAULT); SearchHit[] hits = response.getHits().getHits(); List<T> res = new ArrayList<>(hits.length); for (SearchHit hit : hits) { res.add(JSON.parseObject(hit.getSourceAsString(), c)); } return res; } catch (Exception e) { throw new RuntimeException(e); } }
Example #24
Source File: MatchParseApiMain.java From elasticsearch-pool with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ QueryBuilder matchQueryBuilder = QueryBuilders.matchPhraseQuery("content","校车"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(matchQueryBuilder); searchSourceBuilder.from(0); searchSourceBuilder.size(5); SearchRequest searchRequest = new SearchRequest("jingma2");//限定index searchRequest.types("fulltext");//限定type searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); }finally{ HighLevelClient.close(); } }
Example #25
Source File: ExistApiMain.java From elasticsearch-pool with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ ExistsQueryBuilder matchQueryBuilder = QueryBuilders.existsQuery("retcode");//查询某个字段存在的记录 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(matchQueryBuilder); searchSourceBuilder.from(0); searchSourceBuilder.size(1); SearchRequest searchRequest = new SearchRequest("serverlog_20180701");//限定index searchRequest.types("log");//限定type searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); }finally{ HighLevelClient.close(); } }
Example #26
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * 非同期でドキュメントを検索. * @param index インデックス名 * @param routingId routingId * @param query クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch( String index, String routingId, QueryBuilder query) { SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT); String queryString = "null"; if (query != null) { req.source(new SearchSourceBuilder().query(query)); queryString = query.buildAsBytes().toUtf8(); } if (routingFlag) { req = req.routing(routingId); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, null, null, queryString, "Search"); return ret; }
Example #27
Source File: MetadataBackendKV.java From heroic with Apache License 2.0 | 6 votes |
@Override public AsyncFuture<CountSeries> countSeries(final CountSeries.Request filter) { return doto(c -> { final OptionalLimit limit = filter.getLimit(); if (limit.isZero()) { return async.resolved(new CountSeries()); } final QueryBuilder f = filter(filter.getFilter()); SearchRequest request = c.getIndex().count(METADATA_TYPE); SearchSourceBuilder sourceBuilder = request.source(); limit.asInteger().ifPresent(sourceBuilder::terminateAfter); sourceBuilder.query(new BoolQueryBuilder().must(f)); final ResolvableFuture<SearchResponse> future = async.future(); c.execute(request, bind(future)); return future.directTransform( r -> new CountSeries(r.getHits().getTotalHits().value, false)); }); }
Example #28
Source File: AbstractEs6_4ClientInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
protected SearchResponse doRollupSearch(SearchRequest searchRequest) throws IOException, ExecutionException, InterruptedException { if (async) { ClientMethod<SearchRequest, SearchResponse> method = (request, options, listener) -> client.rollup().searchAsync(request, options, listener); return invokeAsync(searchRequest, method); } return client.rollup().search(searchRequest, RequestOptions.DEFAULT); }
Example #29
Source File: TransportConnection.java From heroic with Apache License 2.0 | 5 votes |
@Override public void execute( @NotNull SearchRequest request, @NotNull ActionListener<SearchResponse> listener ) { client.search(request, listener); }
Example #30
Source File: RestDataAction.java From elasticsearch-dataformat with Apache License 2.0 | 5 votes |
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { SearchRequest searchRequest = new SearchRequest(); request.withContentOrSourceParamParserOrNull( parser -> RestSearchAction.parseSearchRequest(searchRequest, request, parser, size -> searchRequest.source().size(size))); if (request.paramAsInt("size", -1) == -1) { searchRequest.source().size(100); } final String file = request.param("file"); final long limitBytes; String limitParamStr = request.param("limit"); if (Strings.isNullOrEmpty(limitParamStr)) { limitBytes = defaultLimit; } else { if (limitParamStr.endsWith("%")) { limitParamStr = limitParamStr.substring(0, limitParamStr.length() - 1); } limitBytes = (long) (maxMemory * (Float.parseFloat(limitParamStr) / 100F)); } final ContentType contentType = getContentType(request); if (contentType == null) { final String msg = "Unknown content type:" + request.header("Content-Type"); throw new IllegalArgumentException(msg); } final DataContent dataContent = contentType.dataContent(client, request); return channel -> client.search(searchRequest, new SearchResponseListener( channel, file, limitBytes, dataContent)); }