Package org.nuxeo.elasticsearch.query
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 Summary
Fields Modifier and Type Field Description protected static String
AGG_FILTER_SUFFIX
protected List<AggregateEsBase<org.elasticsearch.search.aggregations.Aggregation,Bucket>>
aggregates
protected static int
DEFAULT_LIMIT
protected boolean
esOnly
protected org.elasticsearch.index.query.QueryBuilder
esQueryBuilder
protected boolean
fetchFromElasticsearch
protected List<String>
highlightFields
protected EsFetcher.HitDocConsumer
hitDocConsumer
protected int
limit
protected String
nxql
protected int
offset
protected List<String>
repositories
protected boolean
returnsDocuments
protected boolean
searchOnAllRepo
protected String[]
selectFields
protected Map<String,Type>
selectFieldsAndTypes
protected CoreSession
session
protected List<SortInfo>
sortInfos
protected boolean
useUnrestrictedSession
-
Constructor Summary
Constructors Constructor Description NxQueryBuilder(CoreSession coreSession)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NxQueryBuilder
addAggregate(AggregateEsBase<? extends org.elasticsearch.search.aggregations.Aggregation,? extends Bucket> aggregate)
NxQueryBuilder
addAggregates(List<AggregateEsBase<? extends org.elasticsearch.search.aggregations.Aggregation,? extends Bucket>> aggregates)
NxQueryBuilder
addSearchRepository(String repositoryName)
Add a specific repository to search.protected org.elasticsearch.index.query.QueryBuilder
addSecurityFilter(org.elasticsearch.index.query.QueryBuilder query)
NxQueryBuilder
addSort(SortInfo sortInfo)
NxQueryBuilder
addSort(SortInfo[] sortInfos)
NxQueryBuilder
esQuery(org.elasticsearch.index.query.QueryBuilder queryBuilder)
Build the query using the Elasticsearch QueryBuilder API.NxQueryBuilder
fetchFromDatabase()
Fetch the documents using VCS (database) engine.NxQueryBuilder
fetchFromElasticsearch()
Ask for the Elasticsearch _source field, use it to build documents.protected org.elasticsearch.index.query.QueryBuilder
getAggregateFilter()
protected org.elasticsearch.index.query.QueryBuilder
getAggregateFilterExceptFor(String id)
static String
getAggregateFilterId(Aggregate<?> agg)
List<AggregateEsBase<org.elasticsearch.search.aggregations.Aggregation,Bucket>>
getAggregates()
List<org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder>
getEsAggregates()
Fetcher
getFetcher(org.elasticsearch.action.search.SearchResponse response, Map<String,String> repoNames)
protected Fetcher
getFetcher(CoreSession session, org.elasticsearch.action.search.SearchResponse response, Map<String,String> repoNames)
int
getLimit()
String
getNxql()
int
getOffset()
List<String>
getSearchRepositories()
Return the list of repositories to search, or an empty list to search on all available repositories;String[]
getSelectFields()
Map<String,Type>
getSelectFieldsAndTypes()
CoreSession
getSession()
org.elasticsearch.search.sort.SortBuilder<?>[]
getSortBuilders()
List<SortInfo>
getSortInfos()
protected String
guessFieldType(String field)
NxQueryBuilder
highlight(List<String> highlightFields)
NxQueryBuilder
hitDocConsumer(EsFetcher.HitDocConsumer consumer)
If search results are found, use this SearchHit and DocumentModel consumer on each hit.boolean
isFetchFromElasticsearch()
NxQueryBuilder
limit(int limit)
No more than that many documents will be returned.org.elasticsearch.index.query.QueryBuilder
makeQuery()
Get the Elasticsearch queryBuilder.NxQueryBuilder
nxql(String nxql)
Build the query from a NXQL string.protected boolean
nxqlHasSelectClause(String nxql)
NxQueryBuilder
offset(int offset)
Says to skip that many documents before beginning to return documents.NxQueryBuilder
onlyElasticsearchResponse()
Don't return document model list, aggregates or rows, only the original Elasticsearch response is accessible fromEsResult.getElasticsearchResponse()
boolean
returnsDocuments()
boolean
returnsRows()
NxQueryBuilder
searchOnAllRepositories()
Search on all available repositories.void
updateRequest(org.elasticsearch.search.builder.SearchSourceBuilder request)
NxQueryBuilder
useUnrestrictedSession(boolean useUnrestrictedSession)
-
-
-
Field Detail
-
DEFAULT_LIMIT
protected static final int DEFAULT_LIMIT
- See Also:
- Constant Field Values
-
AGG_FILTER_SUFFIX
protected static final String AGG_FILTER_SUFFIX
- See Also:
- Constant Field Values
-
session
protected final CoreSession session
-
aggregates
protected final List<AggregateEsBase<org.elasticsearch.search.aggregations.Aggregation,Bucket>> aggregates
-
limit
protected int limit
-
offset
protected int offset
-
nxql
protected String nxql
-
esQueryBuilder
protected org.elasticsearch.index.query.QueryBuilder esQueryBuilder
-
fetchFromElasticsearch
protected boolean fetchFromElasticsearch
-
searchOnAllRepo
protected boolean searchOnAllRepo
-
selectFields
protected String[] selectFields
-
returnsDocuments
protected boolean returnsDocuments
-
esOnly
protected boolean esOnly
-
hitDocConsumer
protected EsFetcher.HitDocConsumer hitDocConsumer
-
useUnrestrictedSession
protected boolean useUnrestrictedSession
-
-
Constructor Detail
-
NxQueryBuilder
public NxQueryBuilder(CoreSession coreSession)
-
-
Method Detail
-
limit
public NxQueryBuilder limit(int limit)
No more than that many documents will be returned. Default to {DEFAULT_LIMIT}. Since Nuxeo 8.4 and ES 2.x, we can not give -1 to this method as the default configuration on ES allows to have a search window of 10000 documents at maximum. 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.elasticsearch.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 fromEsResult.getElasticsearchResponse()
- Since:
- 7.3
-
addAggregate
public NxQueryBuilder addAggregate(AggregateEsBase<? extends org.elasticsearch.search.aggregations.Aggregation,? extends Bucket> aggregate)
-
addAggregates
public NxQueryBuilder addAggregates(List<AggregateEsBase<? extends org.elasticsearch.search.aggregations.Aggregation,? extends Bucket>> aggregates)
-
highlight
public NxQueryBuilder highlight(List<String> highlightFields)
- Since:
- 9.1
-
getLimit
public int getLimit()
-
getOffset
public int getOffset()
-
getNxql
public String getNxql()
-
isFetchFromElasticsearch
public boolean isFetchFromElasticsearch()
-
getSession
public CoreSession getSession()
-
makeQuery
public org.elasticsearch.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.elasticsearch.search.sort.SortBuilder<?>[] getSortBuilders()
-
getAggregateFilter
protected org.elasticsearch.index.query.QueryBuilder getAggregateFilter()
-
getAggregateFilterExceptFor
protected org.elasticsearch.index.query.QueryBuilder getAggregateFilterExceptFor(String id)
-
getAggregates
public List<AggregateEsBase<org.elasticsearch.search.aggregations.Aggregation,Bucket>> getAggregates()
-
getEsAggregates
public List<org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder> getEsAggregates()
-
updateRequest
public void updateRequest(org.elasticsearch.search.builder.SearchSourceBuilder request)
-
addSecurityFilter
protected org.elasticsearch.index.query.QueryBuilder addSecurityFilter(org.elasticsearch.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.elasticsearch.action.search.SearchResponse response, Map<String,String> repoNames)
- Since:
- 6.0
-
getFetcher
protected Fetcher getFetcher(CoreSession session, org.elasticsearch.action.search.SearchResponse response, Map<String,String> repoNames)
-
getSelectFields
public String[] getSelectFields()
- Since:
- 7.2
-
returnsDocuments
public boolean returnsDocuments()
- Since:
- 7.2
-
returnsRows
public boolean returnsRows()
-
-