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 queryBuilder
054     * @param keepAlive the search context lifetime
055     * @return an {@link EsScrollResult} including the search results and a scroll id, to be passed to the subsequent
056     *         calls to {@link #scroll(EsScrollResult)}
057     * @since 8.3
058     */
059    EsScrollResult scroll(NxQueryBuilder queryBuilder, long keepAlive);
060
061    /**
062     * Retrieves the next batch of results of a scrollable search request for the given {@link EsScrollResult}.
063     *
064     * @return an {@link EsScrollResult} including the search results and a scroll id, to be passed to the subsequent
065     *         calls to {@link #scroll(EsScrollResult)}
066     * @since 8.3
067     */
068    EsScrollResult scroll(EsScrollResult scrollResult);
069
070    /**
071     * Clear scroll on ElasticSearch cluster for the given {@link EsScrollResult}.
072     *
073     * @since 8.4
074     */
075    void clearScroll(EsScrollResult scrollResult);
076
077    /**
078     * Returns a document list using an NXQL query. Fetch documents from the VCS repository.
079     *
080     * @since 5.9.3
081     * @deprecated since 6.0, use query with NxQueryBuilder
082     */
083    @Deprecated
084    DocumentModelList query(CoreSession session, String nxql, int limit, int offset, SortInfo... sortInfos);
085
086    /**
087     * Returns a document list using an ElasticSearch {@link QueryBuilder}. Fetch documents from the VCS repository.
088     *
089     * @since 5.9.3
090     * @deprecated since 6.0, use query with NxQueryBuilder
091     */
092    @Deprecated
093    DocumentModelList query(CoreSession session, QueryBuilder queryBuilder, int limit, int offset,
094            SortInfo... sortInfos);
095
096}