use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project yacy_grid_mcp by yacy.
the class YaCyQuery method exactMatchQueryBuilder.
public static QueryBuilder exactMatchQueryBuilder(String q, Boosts boosts) {
BoolQueryBuilder qb = QueryBuilders.boolQuery();
boosts.forEach((mapping, boost) -> qb.should(QueryBuilders.termQuery(mapping.getMapping().name(), q)));
qb.minimumShouldMatch(1);
return qb;
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project yacy_grid_mcp by yacy.
the class ElasticsearchClient method query.
public Map<String, Object> query(final String indexName, final String typeName, final String field_name, String field_value) {
if (field_value == null || field_value.length() == 0)
return null;
// prepare request
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.filter(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(field_name, field_value)));
return query(indexName, typeName, query);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project yacy_grid_mcp by yacy.
the class ElasticsearchClient method queryWithConstraints.
public List<Map<String, Object>> queryWithConstraints(final String indexName, final String fieldName, final String fieldValue, final Map<String, String> constraints, boolean latest) throws IOException {
SearchRequestBuilder request = this.elasticsearchClient.prepareSearch(indexName).setSearchType(SearchType.QUERY_THEN_FETCH).setFrom(0);
BoolQueryBuilder bFilter = QueryBuilders.boolQuery();
bFilter.filter(QueryBuilders.constantScoreQuery(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(fieldName, fieldValue))));
for (Object o : constraints.entrySet()) {
@SuppressWarnings("rawtypes") Map.Entry entry = (Map.Entry) o;
bFilter.filter(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery((String) entry.getKey(), ((String) entry.getValue()).toLowerCase())));
}
request.setQuery(bFilter);
// get response
SearchResponse response = request.execute().actionGet();
// evaluate search result
ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
SearchHit[] hits = response.getHits().getHits();
for (SearchHit hit : hits) {
Map<String, Object> map = hit.getSourceAsMap();
result.add(map);
}
return result;
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class RuleIndex method search.
public SearchIdResult<String> search(RuleQuery query, SearchOptions options) {
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
QueryBuilder qb = buildQuery(query);
Map<String, QueryBuilder> filters = buildFilters(query);
if (!options.getFacets().isEmpty()) {
for (AggregationBuilder aggregation : getFacets(query, options, qb, filters).values()) {
sourceBuilder.aggregation(aggregation);
}
}
setSorting(query, sourceBuilder);
setPagination(options, sourceBuilder);
BoolQueryBuilder fb = boolQuery();
for (QueryBuilder filterBuilder : filters.values()) {
fb.must(filterBuilder);
}
sourceBuilder.query(boolQuery().must(qb).filter(fb));
SearchRequest esSearch = EsClient.prepareSearch(TYPE_RULE).source(sourceBuilder);
return new SearchIdResult<>(client.search(esSearch), input -> input, system2.getDefaultTimeZone().toZoneId());
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class UserIndex method search.
public SearchResult<UserDoc> search(UserQuery userQuery, SearchOptions options) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(options.getLimit()).from(options.getOffset()).sort(FIELD_NAME, SortOrder.ASC);
BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, true));
QueryBuilder esQuery = matchAllQuery();
Optional<String> textQuery = userQuery.getTextQuery();
if (textQuery.isPresent()) {
esQuery = QueryBuilders.multiMatchQuery(textQuery.get(), FIELD_LOGIN, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN), FIELD_NAME, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME), FIELD_EMAIL, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL)).operator(Operator.AND);
}
SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER).source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
}
Aggregations