Search in sources :

Example 71 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method appendSearchQuery.

private static QueryBuilder appendSearchQuery(final SearchQuery searchQuery, final BoolQueryBuilder filterBoolQueryBuilder) {
    final QueryBuilder queryBuilder = translateToQueryBuilder(searchQuery.getListFilter());
    filterBoolQueryBuilder.must(queryBuilder);
    return queryBuilder;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 72 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method appendSearchQuery.

private static void appendSearchQuery(final SearchQuery searchQuery, final SearchRequestBuilder searchRequestBuilder, final boolean useHighlight) {
    final BoolQueryBuilder filterBoolQueryBuilder = QueryBuilders.boolQuery();
    final BoolQueryBuilder postFilterBoolQueryBuilder = QueryBuilders.boolQuery();
    // on ajoute les critères de la recherche AVEC impact sur le score
    final QueryBuilder queryBuilder = appendSearchQuery(searchQuery, filterBoolQueryBuilder);
    // on ajoute les filtres de sécurité SANS impact sur le score
    appendSecurityFilter(searchQuery.getSecurityListFilter(), filterBoolQueryBuilder);
    // on ajoute les filtres des facettes SANS impact sur le score
    appendSelectedFacetValues(searchQuery.getFacetedQuery(), filterBoolQueryBuilder, postFilterBoolQueryBuilder);
    final QueryBuilder requestQueryBuilder;
    if (searchQuery.isBoostMostRecent()) {
        requestQueryBuilder = appendBoostMostRecent(searchQuery, queryBuilder);
    } else {
        requestQueryBuilder = filterBoolQueryBuilder;
    }
    searchRequestBuilder.setQuery(requestQueryBuilder).setPostFilter(postFilterBoolQueryBuilder);
    if (useHighlight) {
        // .setHighlighterFilter(true) //We don't highlight the security filter
        // .addHighlightedField("*"); HOW TO ?
        searchRequestBuilder.highlighter(new HighlightBuilder().numOfFragments(3));
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)

Example 73 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method appendSecurityFilter.

private static void appendSecurityFilter(final Optional<ListFilter> securityListFilter, final BoolQueryBuilder filterBoolQueryBuilder) {
    if (securityListFilter.isPresent()) {
        final QueryBuilder securityFilterBuilder = translateToQueryBuilder(securityListFilter.get());
        filterBoolQueryBuilder.filter(securityFilterBuilder);
    // use filteredQuery instead of PostFilter in order to filter aggregations too.
    }
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 74 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project vertexium by visallo.

the class ElasticsearchSearchVertexQuery method getEdgeFilter.

private QueryBuilder getEdgeFilter() {
    switch(direction) {
        case BOTH:
            QueryBuilder inVertexIdFilter = getDirectionInEdgeFilter();
            QueryBuilder outVertexIdFilter = getDirectionOutEdgeFilter();
            return QueryBuilders.boolQuery().should(inVertexIdFilter).should(outVertexIdFilter).minimumShouldMatch(1);
        case OUT:
            return getDirectionOutEdgeFilter();
        case IN:
            return getDirectionInEdgeFilter();
        default:
            throw new VertexiumException("unexpected direction: " + direction);
    }
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 75 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project vertexium by visallo.

the class Elasticsearch5SearchIndex method deleteExtendedDataForElement.

private void deleteExtendedDataForElement(Element element) {
    try {
        QueryBuilder filter = QueryBuilders.termQuery(ELEMENT_ID_FIELD_NAME, element.getId());
        SearchRequestBuilder s = getClient().prepareSearch(getIndicesToQuery()).setTypes(getIdStrategy().getType()).setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).filter(filter)).storedFields(ELEMENT_ID_FIELD_NAME, EXTENDED_DATA_TABLE_NAME_FIELD_NAME, EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
        SearchResponse searchResponse = checkForFailures(s.execute().get());
        for (SearchHit hit : searchResponse.getHits()) {
            if (MUTATION_LOGGER.isTraceEnabled()) {
                LOGGER.trace("deleting extended data document %s", hit.getId());
            }
            getIndexRefreshTracker().pushChange(hit.getIndex());
            getClient().prepareDelete(hit.getIndex(), hit.getType(), hit.getId()).execute().actionGet();
        }
    } catch (Exception ex) {
        throw new VertexiumException("Could not delete extended data for element: " + element.getId());
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) NodeValidationException(org.elasticsearch.node.NodeValidationException) UnknownHostException(java.net.UnknownHostException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)371 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)245 Test (org.testng.annotations.Test)156 DynamicEntity (org.molgenis.data.support.DynamicEntity)137 SearchResponse (org.elasticsearch.action.search.SearchResponse)58 QueryImpl (org.molgenis.data.support.QueryImpl)36 Map (java.util.Map)32 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)29 HashMap (java.util.HashMap)27 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)27 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)27 IOException (java.io.IOException)23 SearchHit (org.elasticsearch.search.SearchHit)22 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)19 List (java.util.List)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15