public ElasticIndexResponse Index <T>(T entity) where T : class { int retryCount = 0; Exception lastException = null; while (retryCount < MaxRetry) { try { IIndexResponse indexResponse = _client.Index(entity); if (indexResponse != null && indexResponse.IsValid) { throw new ElasticSearchServerException(indexResponse.ServerError.Error); } ElasticIndexResponse response = new ElasticIndexResponse(); return(response); } catch (WebException wex) { lastException = wex; } catch (Exception ex) { lastException = ex; } retryCount++; Thread.Sleep(500); } throw new ElasticSearchException("There was an error occured while indexing", lastException); }
public ElasticIndexResponse ExecuteCreateOrUpdateRequest <T>(T @object, string esType) where T : class, IGuidedEntity { try { var client = GetElasticClient(); var response = client.Index(@object, i => i.Index(EsIndex).Type(esType).Id(@object.Guid)); return(response.ApiCall.Success ? ElasticIndexResponse.SuccessResponse(response) : ElasticIndexResponse.FailResponse(response.ApiCall.OriginalException.Message)); } catch { return(ElasticIndexResponse.FailResponse(ServerErrorMessage)); } }