use of org.elasticsearch.action.search.SearchRequestBuilder in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiSearch.
@Test
public void testMultiSearch() throws Exception {
//first, INDEX two values
Map<String, Object> headers = new HashMap<String, Object>();
node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram").setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
List<SearchRequest> list = new ArrayList<>();
list.add(srb1.request());
list.add(srb2.request());
list.add(srb3.request());
MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
MultiSearchResponse.Item[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
assertFalse("response 1 should be ok", responses[0].isFailure());
assertFalse("response 2 should be ok", responses[1].isFailure());
assertTrue("response 3 should be failed", responses[2].isFailure());
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiSearch.
@Test
public void testMultiSearch() throws Exception {
//first, INDEX two values
Map<String, Object> headers = new HashMap<String, Object>();
node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram").setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
List<SearchRequest> list = new ArrayList<>();
list.add(srb1.request());
list.add(srb2.request());
list.add(srb3.request());
MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
MultiSearchResponse.Item[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
assertFalse("response 1 should be ok", responses[0].isFailure());
assertFalse("response 2 should be ok", responses[1].isFailure());
assertTrue("response 3 should be failed", responses[2].isFailure());
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ComponentIndex method search.
@VisibleForTesting
List<ComponentsPerQualifier> search(ComponentIndexQuery query, ComponentTextSearchFeature... features) {
Collection<String> qualifiers = query.getQualifiers();
if (qualifiers.isEmpty()) {
return Collections.emptyList();
}
SearchRequestBuilder request = client.prepareSearch(INDEX_TYPE_COMPONENT).setQuery(createQuery(query, features)).addAggregation(createAggregation(query)).setSize(0);
SearchResponse response = request.get();
return aggregationsToQualifiers(response);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class IssueIndex method listTermsMatching.
private Terms listTermsMatching(String fieldName, IssueQuery query, @Nullable String textQuery, Terms.Order termsOrder, int maxNumberOfTags) {
SearchRequestBuilder requestBuilder = getClient().prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE).setSize(0);
requestBuilder.setQuery(boolQuery().must(QueryBuilders.matchAllQuery()).filter(createBoolFilter(query)));
TermsBuilder aggreg = AggregationBuilders.terms("_ref").field(fieldName).size(maxNumberOfTags).order(termsOrder).minDocCount(1L);
if (textQuery != null) {
aggreg.include(format(SUBSTRING_MATCH_REGEXP, escapeSpecialRegexChars(textQuery)));
}
SearchResponse searchResponse = requestBuilder.addAggregation(aggreg).get();
return searchResponse.getAggregations().get("_ref");
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class IssueIndex method selectIssuesForBatch.
/**
* Return non closed issues for a given project, module, or file. Other kind of components are not allowed.
* Only fields needed for the batch are returned.
*/
public Iterator<IssueDoc> selectIssuesForBatch(ComponentDto component) {
BoolQueryBuilder filter = boolQuery().must(createAuthorizationFilter(true)).mustNot(termsQuery(IssueIndexDefinition.FIELD_ISSUE_STATUS, Issue.STATUS_CLOSED));
switch(component.scope()) {
case Scopes.PROJECT:
filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, component.uuid()));
break;
case Scopes.FILE:
filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, component.uuid()));
break;
default:
throw new IllegalStateException(format("Component of scope '%s' is not allowed", component.scope()));
}
SearchRequestBuilder requestBuilder = getClient().prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE).setSearchType(SearchType.SCAN).setScroll(TimeValue.timeValueMinutes(EsUtils.SCROLL_TIME_IN_MINUTES)).setSize(10_000).setFetchSource(new String[] { IssueIndexDefinition.FIELD_ISSUE_KEY, IssueIndexDefinition.FIELD_ISSUE_RULE_KEY, IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID, IssueIndexDefinition.FIELD_ISSUE_FILE_PATH, IssueIndexDefinition.FIELD_ISSUE_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_MANUAL_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_RESOLUTION, IssueIndexDefinition.FIELD_ISSUE_STATUS, IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE, IssueIndexDefinition.FIELD_ISSUE_LINE, IssueIndexDefinition.FIELD_ISSUE_MESSAGE, IssueIndexDefinition.FIELD_ISSUE_CHECKSUM, IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT }, null).setQuery(boolQuery().must(matchAllQuery()).filter(filter));
SearchResponse response = requestBuilder.get();
return EsUtils.scroll(getClient(), response.getScrollId(), DOC_CONVERTER);
}
Aggregations