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 java.util.List;
024
025import org.nuxeo.elasticsearch.commands.IndexingCommand;
026
027/**
028 * Interface to process indexing of documents
029 *
030 * @since 5.9.3
031 */
032public interface ElasticSearchIndexing {
033
034    /**
035     * Run a worker to process the {@link IndexingCommand}.
036     * <p>
037     * Asynchronous command schedules an indexing job and return.
038     * </p>
039     * <p>
040     * Synchronous command execute an indexing job using a new Tx then refresh the index so the document is searchable
041     * immediately. if the command is also recursive the children are processed asynchronously.
042     * </p>
043     * <p>
044     * If there is more than one cmd the elasticsearch request is done in bulk mode.
045     * </p>
046     *
047     * @since 7.1
048     */
049    void runIndexingWorker(List<IndexingCommand> cmds);
050
051    /**
052     * Reindex documents matching the NXQL query, This is done in an asynchronous job.
053     *
054     * @since 7.1
055     */
056    default void runReindexingWorker(String repositoryName, String nxql) {
057        runReindexingWorker(repositoryName, nxql, false);
058    }
059
060    /**
061     * Reindex documents matching the NXQL query, This is done in an asynchronous job. When syncAlias is true a call is
062     * made to sync the search alias with write alias once indexing is done.
063     *
064     * @since 9.3
065     */
066    void runReindexingWorker(String repositoryName, String nxql, boolean syncAlias);
067
068    /**
069     * Recreate an index and run an async reindexing worker.
070     *
071     * @since 9.3
072     */
073    void reindexRepository(String repositoryName);
074
075    /**
076     * Process the {@link IndexingCommand}.
077     * <p>
078     * Send indexing command to Elasticsearch, if the command is synchronous the index is refreshed so the document is
079     * searchable immediately. Recursive indexing is not taken in account except for deletion. This is not a
080     * transactional operation, a rollback will not discard the executed commands.
081     * </p>
082     *
083     * @since 7.1
084     */
085    void indexNonRecursive(IndexingCommand cmd);
086
087    /**
088     * Same as {@link ElasticSearchIndexing#indexNonRecursive(org.nuxeo.elasticsearch.commands.IndexingCommand)} but
089     * process the list command using a bulk request.
090     * </p>
091     *
092     * @since 7.1
093     */
094    void indexNonRecursive(List<IndexingCommand> cmds);
095
096}