use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder in project incubator-skywalking by apache.
the class ServiceReferenceEsMetricUIDAO method getFrontServices.
@Override
public List<ServiceReferenceMetric> getFrontServices(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource, int behindServiceId) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, behindServiceId));
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ServiceReferenceMetric> referenceMetrics = new LinkedList<>();
Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID);
buildNodeByBehindServiceId(referenceMetrics, frontServiceIdTerms, behindServiceId);
return referenceMetrics;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder in project incubator-skywalking by apache.
the class ServiceNameEsCacheDAO method getServiceId.
@Override
public int getServiceId(int applicationId, int srcSpanType, String serviceName) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE);
searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, srcSpanType));
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, serviceName));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(1);
SearchResponse searchResponse = searchRequestBuilder.get();
if (searchResponse.getHits().totalHits > 0) {
SearchHit searchHit = searchResponse.getHits().iterator().next();
return (int) searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID);
}
return 0;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder in project nuxeo-drive-server by nuxeo.
the class ESAuditChangeFinder method getDriveLogsQueryClause.
protected BoolQueryBuilder getDriveLogsQueryClause() {
BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery();
filterBuilder.must(QueryBuilders.termQuery("category", "NuxeoDrive"));
filterBuilder.mustNot(QueryBuilders.termQuery("eventId", "rootUnregistered"));
return filterBuilder;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder in project opencast by opencast.
the class AbstractElasticsearchQueryBuilder method createQuery.
/**
* Create the actual query. We start with a query that matches everything, then move to the boolean conditions,
* finally add filter queries.
*/
private void createQuery() {
queryBuilder = new MatchAllQueryBuilder();
// The boolean query builder
BoolQueryBuilder booleanQuery = new BoolQueryBuilder();
// Terms
if (searchTerms != null) {
for (Map.Entry<String, Set<Object>> entry : searchTerms.entrySet()) {
Set<Object> values = entry.getValue();
if (values.size() == 1)
booleanQuery.must(new TermsQueryBuilder(entry.getKey(), values.iterator().next()));
else
booleanQuery.must(new TermsQueryBuilder(entry.getKey(), values.toArray(new String[values.size()])));
}
this.queryBuilder = booleanQuery;
}
// Negative terms
if (negativeSearchTerms != null) {
for (Map.Entry<String, Set<Object>> entry : negativeSearchTerms.entrySet()) {
Set<Object> values = entry.getValue();
if (values.size() == 1)
booleanQuery.mustNot(new TermsQueryBuilder(entry.getKey(), values.iterator().next()));
else
booleanQuery.mustNot(new TermsQueryBuilder(entry.getKey(), values.toArray(new String[values.size()])));
}
this.queryBuilder = booleanQuery;
}
// Date ranges
if (dateRanges != null) {
for (DateRange dr : dateRanges) {
booleanQuery.must(dr.getQueryBuilder());
}
this.queryBuilder = booleanQuery;
}
// Text
if (text != null) {
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryString(text).field(TEXT);
booleanQuery.must(queryBuilder);
this.queryBuilder = booleanQuery;
}
// Fuzzy text
if (fuzzyText != null) {
FuzzyLikeThisQueryBuilder fuzzyQueryBuilder = QueryBuilders.fuzzyLikeThisQuery(TEXT_FUZZY).likeText(fuzzyText);
booleanQuery.must(fuzzyQueryBuilder);
this.queryBuilder = booleanQuery;
}
QueryBuilder unfilteredQuery = queryBuilder;
List<FilterBuilder> filters = new ArrayList<FilterBuilder>();
// Add filtering for AND terms
if (groups != null) {
for (ValueGroup group : groups) {
filters.addAll(group.getFilterBuilders());
}
}
// Non-Empty fields
if (nonEmptyFields != null) {
for (String field : nonEmptyFields) {
filters.add(FilterBuilders.existsFilter(field));
}
}
// Empty fields
if (emptyFields != null) {
for (String field : emptyFields) {
filters.add(FilterBuilders.missingFilter(field));
}
}
// Filter expressions
if (filter != null) {
filters.add(FilterBuilders.termFilter(IndexSchema.TEXT, filter));
}
// Apply the filters
if (filters.size() == 1) {
this.queryBuilder = QueryBuilders.filteredQuery(unfilteredQuery, filters.get(0));
} else if (filters.size() > 1) {
FilterBuilder andFilter = FilterBuilders.andFilter(filters.toArray(new FilterBuilder[filters.size()]));
this.queryBuilder = QueryBuilders.filteredQuery(unfilteredQuery, andFilter);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder in project muikku by otavanopisto.
the class ElasticSearchProvider method searchWorkspaces.
@Override
public SearchResult searchWorkspaces(String schoolDataSource, String subjectIdentifier, int courseNumber) {
BoolQueryBuilder query = boolQuery();
query.must(termQuery("published", Boolean.TRUE));
query.must(termQuery("subjectIdentifier", subjectIdentifier));
query.must(termQuery("courseNumber", courseNumber));
// query.must(termQuery("access", WorkspaceAccess.LOGGED_IN));
SearchRequestBuilder requestBuilder = elasticClient.prepareSearch("muikku").setTypes("Workspace").setFrom(0).setSize(50).setQuery(query);
// logger.log(Level.INFO, "searchWorkspaces query: " + requestBuilder.internalBuilder());
SearchResponse response = requestBuilder.execute().actionGet();
List<Map<String, Object>> searchResults = new ArrayList<Map<String, Object>>();
SearchHits searchHits = response.getHits();
SearchHit[] results = searchHits.getHits();
long totalHits = searchHits.getTotalHits();
for (SearchHit hit : results) {
Map<String, Object> hitSource = hit.getSource();
hitSource.put("indexType", hit.getType());
searchResults.add(hitSource);
}
SearchResult result = new SearchResult(0, 50, searchResults, totalHits);
return result;
}
Aggregations