001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     tdelprat
018 *     bdelbosc
019 */
020
021package org.nuxeo.elasticsearch.api;
022
023import org.elasticsearch.index.query.QueryBuilder;
024import org.nuxeo.ecm.core.api.CoreSession;
025import org.nuxeo.ecm.core.api.DocumentModelList;
026import org.nuxeo.ecm.core.api.SortInfo;
027import org.nuxeo.elasticsearch.query.NxQueryBuilder;
028
029/**
030 * Interface to search on documents
031 *
032 * @since 5.9.3
033 */
034public interface ElasticSearchService {
035
036    /**
037     * Returns a document list using an {@link NxQueryBuilder}.
038     *
039     * @since 5.9.5
040     */
041    DocumentModelList query(NxQueryBuilder queryBuilder);
042
043    /**
044     * Returns documents and aggregates.
045     *
046     * @since 6.0
047     */
048    EsResult queryAndAggregate(NxQueryBuilder queryBuilder);
049
050    /**
051     * Performs the initial search of a scrollable search request using an {@link NxQueryBuilder}.
052     *
053     * @param keepAlive the search context lifetime
054     * @return an {@link EsScrollResult} including the search results and a scroll id, to be passed to the subsequent
055     *         calls to {@link #scroll(EsScrollResult)}
056     * @since 8.3
057     */
058    EsScrollResult scroll(NxQueryBuilder queryBuilder, long keepAlive);
059
060    /**
061     * Retrieves the next batch of results of a scrollable search request for the given {@link EsScrollResult}.
062     *
063     * @return an {@link EsScrollResult} including the search results and a scroll id, to be passed to the subsequent
064     *         calls to {code scroll}.
065     * @since 8.3
066     */
067    EsScrollResult scroll(EsScrollResult scrollResult);
068
069    /**
070     * Clear scroll on ElasticSearch cluster for the given {@link EsScrollResult}.
071     *
072     * @since 8.4
073     */
074    void clearScroll(EsScrollResult scrollResult);
075
076    /**
077     * Returns a document list using an NXQL query. Fetch documents from the VCS repository.
078     *
079     * @since 5.9.3
080     * @deprecated since 6.0, use query with NxQueryBuilder
081     */
082    @Deprecated
083    DocumentModelList query(CoreSession session, String nxql, int limit, int offset, SortInfo... sortInfos);
084
085    /**
086     * Returns a document list using an ElasticSearch {@link QueryBuilder}. Fetch documents from the VCS repository.
087     *
088     * @since 5.9.3
089     * @deprecated since 6.0, use query with NxQueryBuilder
090     */
091    @Deprecated
092    DocumentModelList query(CoreSession session, QueryBuilder queryBuilder, int limit, int offset,
093            SortInfo... sortInfos);
094
095}