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.BulkProcessor; 022import org.elasticsearch.action.bulk.BulkRequest; 023import org.elasticsearch.action.bulk.BulkResponse; 024import org.elasticsearch.action.delete.DeleteRequest; 025import org.elasticsearch.action.delete.DeleteResponse; 026import org.elasticsearch.action.get.GetRequest; 027import org.elasticsearch.action.get.GetResponse; 028import org.elasticsearch.action.index.IndexRequest; 029import org.elasticsearch.action.index.IndexResponse; 030import org.elasticsearch.action.search.ClearScrollRequest; 031import org.elasticsearch.action.search.ClearScrollResponse; 032import org.elasticsearch.action.search.SearchRequest; 033import org.elasticsearch.action.search.SearchResponse; 034import org.elasticsearch.action.search.SearchScrollRequest; 035import org.elasticsearch.cluster.health.ClusterHealthStatus; 036import org.nuxeo.ecm.core.api.ConcurrentUpdateException; 037 038/** 039 * @since 9.3 040 */ 041public interface ESClient extends AutoCloseable { 042 043 // ------------------------------------------------------------------- 044 // Admin 045 // 046 boolean waitForYellowStatus(String[] indexNames, int timeoutSecond); 047 048 ClusterHealthStatus getHealthStatus(String[] indexNames); 049 050 void refresh(String indexName); 051 052 void flush(String indexName); 053 054 void optimize(String indexName); 055 056 boolean indexExists(String indexName); 057 058 boolean mappingExists(String indexName, String type); 059 060 void deleteIndex(String indexName, int timeoutSecond); 061 062 void createIndex(String indexName, String jsonSettings); 063 064 void createMapping(String indexName, String type, String jsonMapping); 065 066 String getNodesInfo(); 067 068 String getNodesStats(); 069 070 boolean aliasExists(String aliasName); 071 072 /** 073 * Returns the name of the index referenced by the alias. 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 /** 103 * Creates an elasticsearch BulkProcessor builder. 104 * 105 * @since 10.3 106 */ 107 BulkProcessor.Builder bulkProcessorBuilder(BulkProcessor.Listener listener); 108}