Class NxQueryBuilder

java.lang.Object
org.nuxeo.elasticsearch.query.NxQueryBuilder

public class NxQueryBuilder extends Object
Elasticsearch query builder for the Nuxeo ES api.
Since:
5.9.5
  • Field Details

    • DEFAULT_LIMIT

      protected static final int DEFAULT_LIMIT
      See Also:
    • AGG_FILTER_SUFFIX

      protected static final String AGG_FILTER_SUFFIX
      See Also:
    • session

      protected final CoreSession session
    • sortInfos

      protected final List<SortInfo> sortInfos
    • repositories

      protected final List<String> repositories
    • aggregates

      protected final List<AggregateEsBase<org.opensearch.search.aggregations.Aggregation,Bucket>> aggregates
    • limit

      protected int limit
    • offset

      protected int offset
    • nxql

      protected String nxql
    • esQueryBuilder

      protected org.opensearch.index.query.QueryBuilder esQueryBuilder
    • fetchFromElasticsearch

      protected boolean fetchFromElasticsearch
    • searchOnAllRepo

      protected boolean searchOnAllRepo
    • selectFields

      protected String[] selectFields
    • selectFieldsAndTypes

      protected Map<String,Type> selectFieldsAndTypes
    • returnsDocuments

      protected boolean returnsDocuments
    • esOnly

      protected boolean esOnly
    • highlightFields

      protected List<String> highlightFields
    • hitDocConsumer

      protected EsFetcher.HitDocConsumer hitDocConsumer
    • useUnrestrictedSession

      protected boolean useUnrestrictedSession
  • Constructor Details

    • NxQueryBuilder

      public NxQueryBuilder(CoreSession coreSession)
  • Method Details

    • getAggregateFilterId

      public static String getAggregateFilterId(Aggregate<?> agg)
    • limit

      public NxQueryBuilder limit(int limit)
      No more than that many documents will be returned. Default to {DEFAULT_LIMIT}. This settings could be changed on ES by changing {index.max_result_window}, but it is preferable to use the scan & scroll API.
    • offset

      public NxQueryBuilder offset(int offset)
      Says to skip that many documents before beginning to return documents. If both offset and limit appear, then offset documents are skipped before starting to count the limit documents that are returned.
    • addSort

      public NxQueryBuilder addSort(SortInfo sortInfo)
    • addSort

      public NxQueryBuilder addSort(SortInfo[] sortInfos)
    • nxql

      public NxQueryBuilder nxql(String nxql)
      Build the query from a NXQL string. You should either use nxql, either esQuery, not both.
    • esQuery

      public NxQueryBuilder esQuery(org.opensearch.index.query.QueryBuilder queryBuilder)
      Build the query using the Elasticsearch QueryBuilder API. You should either use nxql, either esQuery, not both.
    • fetchFromElasticsearch

      public NxQueryBuilder fetchFromElasticsearch()
      Ask for the Elasticsearch _source field, use it to build documents.
    • hitDocConsumer

      public NxQueryBuilder hitDocConsumer(EsFetcher.HitDocConsumer consumer)
      If search results are found, use this SearchHit and DocumentModel consumer on each hit.
      Since:
      10.2
    • useUnrestrictedSession

      public NxQueryBuilder useUnrestrictedSession(boolean useUnrestrictedSession)
      Since:
      11.1
    • fetchFromDatabase

      public NxQueryBuilder fetchFromDatabase()
      Fetch the documents using VCS (database) engine. This is done by default
    • onlyElasticsearchResponse

      public NxQueryBuilder onlyElasticsearchResponse()
      Don't return document model list, aggregates or rows, only the original Elasticsearch response is accessible from EsResult.getElasticsearchResponse()
      Since:
      7.3
    • addAggregate

      public NxQueryBuilder addAggregate(AggregateEsBase<? extends org.opensearch.search.aggregations.Aggregation,? extends Bucket> aggregate)
    • addAggregates

      public NxQueryBuilder addAggregates(List<AggregateEsBase<? extends org.opensearch.search.aggregations.Aggregation,? extends Bucket>> aggregates)
    • highlight

      public NxQueryBuilder highlight(List<String> highlightFields)
      Since:
      9.1
    • getLimit

      public int getLimit()
    • getOffset

      public int getOffset()
    • getSortInfos

      public List<SortInfo> getSortInfos()
    • getNxql

      public String getNxql()
    • isFetchFromElasticsearch

      public boolean isFetchFromElasticsearch()
    • getSession

      public CoreSession getSession()
    • makeQuery

      public org.opensearch.index.query.QueryBuilder makeQuery()
      Get the Elasticsearch queryBuilder. Note that it returns only the query part without order, limits nor aggregates, use the udpateRequest to get the full request.
    • nxqlHasSelectClause

      protected boolean nxqlHasSelectClause(String nxql)
    • getSortBuilders

      public org.opensearch.search.sort.SortBuilder<?>[] getSortBuilders()
    • guessFieldType

      protected String guessFieldType(String field)
    • getAggregateFilter

      protected org.opensearch.index.query.QueryBuilder getAggregateFilter()
    • getAggregateFilterExceptFor

      protected org.opensearch.index.query.QueryBuilder getAggregateFilterExceptFor(String id)
    • getAggregates

      public List<AggregateEsBase<org.opensearch.search.aggregations.Aggregation,Bucket>> getAggregates()
    • getEsAggregates

      public List<org.opensearch.search.aggregations.bucket.filter.FilterAggregationBuilder> getEsAggregates()
    • updateRequest

      public void updateRequest(org.opensearch.search.builder.SearchSourceBuilder request)
    • addSecurityFilter

      protected org.opensearch.index.query.QueryBuilder addSecurityFilter(org.opensearch.index.query.QueryBuilder query)
    • addSearchRepository

      public NxQueryBuilder addSearchRepository(String repositoryName)
      Add a specific repository to search. Default search is done on the session repository only.
      Since:
      6.0
    • searchOnAllRepositories

      public NxQueryBuilder searchOnAllRepositories()
      Search on all available repositories.
      Since:
      6.0
    • getSearchRepositories

      public List<String> getSearchRepositories()
      Return the list of repositories to search, or an empty list to search on all available repositories;
      Since:
      6.0
    • getFetcher

      public Fetcher getFetcher(org.opensearch.action.search.SearchResponse response, Map<String,String> repoNames)
      Since:
      6.0
    • getFetcher

      protected Fetcher getFetcher(CoreSession session, org.opensearch.action.search.SearchResponse response, Map<String,String> repoNames)
    • getSelectFields

      public String[] getSelectFields()
      Since:
      7.2
    • getSelectFieldsAndTypes

      public Map<String,Type> getSelectFieldsAndTypes()
      Since:
      7.2
    • returnsDocuments

      public boolean returnsDocuments()
      Since:
      7.2
    • returnsRows

      public boolean returnsRows()