001/*
002 * (C) Copyright 2017 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 *     bdelbosc
018 */
019package org.nuxeo.elasticsearch.api;
020
021import org.elasticsearch.action.bulk.BulkRequest;
022import org.elasticsearch.action.bulk.BulkResponse;
023import org.elasticsearch.action.delete.DeleteRequest;
024import org.elasticsearch.action.delete.DeleteResponse;
025import org.elasticsearch.action.get.GetRequest;
026import org.elasticsearch.action.get.GetResponse;
027import org.elasticsearch.action.index.IndexRequest;
028import org.elasticsearch.action.index.IndexResponse;
029import org.elasticsearch.action.search.ClearScrollRequest;
030import org.elasticsearch.action.search.ClearScrollResponse;
031import org.elasticsearch.action.search.SearchRequest;
032import org.elasticsearch.action.search.SearchResponse;
033import org.elasticsearch.action.search.SearchScrollRequest;
034import org.elasticsearch.cluster.health.ClusterHealthStatus;
035import org.nuxeo.ecm.core.api.ConcurrentUpdateException;
036
037/**
038 * @since 9.3
039 */
040public interface ESClient extends AutoCloseable {
041
042    // -------------------------------------------------------------------
043    // Admin
044    //
045    boolean waitForYellowStatus(String[] indexNames, int timeoutSecond);
046
047    ClusterHealthStatus getHealthStatus(String[] indexNames);
048
049    void refresh(String indexName);
050
051    void flush(String indexName);
052
053    void optimize(String indexName);
054
055    boolean indexExists(String indexName);
056
057    boolean mappingExists(String indexName, String type);
058
059    void deleteIndex(String indexName, int timeoutSecond);
060
061    void createIndex(String indexName, String jsonSettings);
062
063    void createMapping(String indexName, String type, String jsonMapping);
064
065    String getNodesInfo();
066
067    String getNodesStats();
068
069    boolean aliasExists(String aliasName);
070
071    /**
072     * Returns the name of the index referenced by the alias.
073     * Returns null if the alias does not exists.
074     */
075    String getFirstIndexForAlias(String aliasName);
076
077    void updateAlias(String aliasName, String indexName);
078
079    // -------------------------------------------------------------------
080    // Search
081    //
082
083    BulkResponse bulk(BulkRequest request);
084
085    DeleteResponse delete(DeleteRequest request);
086
087    SearchResponse search(SearchRequest request);
088
089    SearchResponse searchScroll(SearchScrollRequest request);
090
091    GetResponse get(GetRequest request);
092
093    /**
094     * Performs the indexing request.
095     *
096     * @throws ConcurrentUpdateException if a more recent version of the document exits.
097     */
098    IndexResponse index(IndexRequest request);
099
100    ClearScrollResponse clearScroll(ClearScrollRequest request);
101
102}