Search in sources :

Example 56 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project unipop by unipop-graph.

the class DocVertexSchema method getSearch.

@Override
public QueryBuilder getSearch(DeferredVertexQuery query) {
    PredicatesHolder predicatesHolder = this.toPredicates(query.getVertices());
    QueryBuilder queryBuilder = createQueryBuilder(predicatesHolder);
    return queryBuilder;
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 57 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project unipop by unipop-graph.

the class NestedEdgeSchema method createQueryBuilder.

public QueryBuilder createQueryBuilder(SearchVertexQuery query) {
    PredicatesHolder edgePredicates = this.toPredicates(query.getPredicates());
    if (edgePredicates.isAborted())
        return null;
    PredicatesHolder childPredicates = childVertexSchema.toPredicates(query.getVertices());
    childPredicates = PredicatesHolderFactory.and(edgePredicates, childPredicates);
    QueryBuilder childQuery = createNestedQueryBuilder(childPredicates);
    if (query.getDirection().equals(parentDirection.opposite())) {
        if (childPredicates.isAborted())
            return null;
        return childQuery;
    } else if (!query.getDirection().equals(Direction.BOTH))
        childQuery = null;
    PredicatesHolder parentPredicates = parentVertexSchema.toPredicates(query.getVertices());
    QueryBuilder parentQuery = createQueryBuilder(parentPredicates);
    if (parentQuery != null) {
        // if (parentPredicates.isAborted()) return null;
        QueryBuilder edgeQuery = createNestedQueryBuilder(edgePredicates);
        if (edgeQuery != null) {
            parentQuery = QueryBuilders.boolQuery().must(parentQuery).must(edgeQuery);
        }
    }
    if (query.getDirection().equals(parentDirection) && parentPredicates.notAborted())
        return parentQuery;
    else if (childQuery == null && parentPredicates.notAborted())
        return parentQuery;
    else if (parentQuery == null && childPredicates.notAborted())
        return childQuery;
    else if (parentPredicates.isAborted() && childPredicates.isAborted())
        return null;
    else
        return QueryBuilders.boolQuery().should(parentQuery).should(childQuery);
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) NestedQueryBuilder(org.elasticsearch.index.query.NestedQueryBuilder)

Example 58 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project unipop by unipop-graph.

the class NestedVertexSchema method getSearch.

@Override
public QueryBuilder getSearch(DeferredVertexQuery query) {
    PredicatesHolder predicatesHolder = this.toPredicates(query.getVertices());
    QueryBuilder queryBuilder = createQueryBuilder(predicatesHolder);
    return queryBuilder;
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 59 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project unipop by unipop-graph.

the class DocEdgeSchema method getSearch.

@Override
public QueryBuilder getSearch(SearchVertexQuery query) {
    PredicatesHolder edgePredicates = this.toPredicates(query.getPredicates());
    PredicatesHolder vertexPredicates = this.getVertexPredicates(query.getVertices(), query.getDirection());
    PredicatesHolder predicatesHolder = PredicatesHolderFactory.and(edgePredicates, vertexPredicates);
    if (predicatesHolder.isAborted())
        return null;
    QueryBuilder queryBuilder = createQueryBuilder(predicatesHolder);
    return queryBuilder;
// return createSearch(query, queryBuilder);
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 60 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project unipop by unipop-graph.

the class DocumentController method fetchProperties.

@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
    Map<DocumentVertexSchema, QueryBuilder> schemas = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(new SearchCollector<>((schema) -> schema.getSearch(uniQuery)));
    Iterator<Vertex> search = search(uniQuery, schemas);
    Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
    search.forEachRemaining(newVertex -> {
        DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
        if (deferredVertex != null)
            deferredVertex.loadProperties(newVertex);
    });
}
Also used : java.util(java.util) ElasticClient(org.unipop.elastic.common.ElasticClient) LoggerFactory(org.slf4j.LoggerFactory) SimpleController(org.unipop.query.controller.SimpleController) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) RemoveQuery(org.unipop.query.mutation.RemoveQuery) Gson(com.google.gson.Gson) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) TraversalFilter(org.unipop.structure.traversalfilter.TraversalFilter) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) BiConsumer(java.util.function.BiConsumer) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) ElementSchema(org.unipop.schema.element.ElementSchema) UniEdge(org.unipop.structure.UniEdge) io.searchbox.core(io.searchbox.core) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Collector(java.util.stream.Collector) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) UniElement(org.unipop.structure.UniElement) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) BinaryOperator(java.util.function.BinaryOperator) TimeUnit(java.util.concurrent.TimeUnit) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) SortOrder(org.elasticsearch.search.sort.SortOrder) UniGraph(org.unipop.structure.UniGraph) BulkableAction(io.searchbox.action.BulkableAction) PropertyQuery(org.unipop.query.mutation.PropertyQuery) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SearchQuery(org.unipop.query.search.SearchQuery) MetricsRunner(org.unipop.util.MetricsRunner) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

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