public IndexInformation Put(CreateIndexRequest request) { var indexInformation = ecf.CreateCatalogueIndex(request); client.Index(request.ToJson(), i => i.Index("ec_indices").Id(request.IndexName)); return indexInformation; }
public CreateIndexRequestTests() { var request = new CreateIndexRequest("new-index-name") { IndexSettings = new IndexSettings { Settings = new Dictionary<string, object> { {"index.settings", "value"} }, Mappings = new List<RootObjectMapping> { { new RootObjectMapping { Name = "my_root_object", Properties = new Dictionary<PropertyNameMarker, IElasticType> { {"my_field", new StringMapping() { Name = "my_string_field "}} } }} } } }; var response = this._client.CreateIndex(request); this._status = response.ConnectionStatus; }
public void CreateIndex(ElasticClient client) { var createIndexRequest = new CreateIndexRequest("esdemo"); var response = client.CreateIndex(createIndexRequest); var str = string.Empty; Console.WriteLine($" create index = {!response.TryGetServerErrorReason(out str)}"); Console.WriteLine(str); }
public void CreateIndex() { CreateIndexRequest request = new CreateIndexRequest(); request.IndexName = "testindex"; IndexInformation response = service.Put(request); Assert.That(response.Name == "testindex"); Console.Out.Write(JsonConvert.SerializeObject(response)); }
public void CreateIndex() { CreateIndexRequest request = new CreateIndexRequest(); request.IndexName = "testindex"; IndexInformation response = service.Put(request); Assert.That(response.Name == "testindex"); Console.Out.Write(JsonConvert.SerializeObject(response)); }
public ActionResult <CreateIndexResponse> CreateNewIndex([FromBody] CreateIndexRequest model) { m_Logger.Info($"[GET] {APIRoutes.CreateIndexRoute}"); #region Request Model Checks if (string.IsNullOrWhiteSpace(model.SourcePath)) { m_Logger.Debug("Required parameter SourcePath is null, empty or whitespace"); return(BadRequest()); } if (!Directory.Exists(model.SourcePath)) { m_Logger.Debug($"Required parameter SourcePath point to path that doesn't exist: {model.SourcePath}"); return(BadRequest()); } var extensionList = model.FileExtensions.ToList(); if (extensionList.Count == 0) { m_Logger.Debug("Required parameter FileExtensions contains empty list"); return(BadRequest()); } var invalidChars = Path.GetInvalidFileNameChars(); foreach (var ext in extensionList) { if (!ext.StartsWith(".")) { m_Logger.Debug($"Required parameter FileExtensions contains entry which don't start with '.': {ext}"); return(BadRequest()); } foreach (var invalid in invalidChars) { if (ext.Contains(invalid)) { m_Logger.Debug($"Required parameter FileExtensions contains entry with invalid filename chars: {ext}"); return(BadRequest()); } } } #endregion m_Logger.Info($"SourcePath: {model.SourcePath}"); var jobId = BackgroundJob.Enqueue(() => CreateIndex(model, null)); return(new CreateIndexResponse { IndexingJobId = jobId }); }
public static void CreateIndex(string elasticSearchConnectionString, string index, int shards, int replicas) { CreateIndexRequest req = new CreateIndexRequest(index); req.Settings = new IndexSettings { NumberOfReplicas = replicas, NumberOfShards = shards }; var client = new Nest.ElasticClient(new Uri(elasticSearchConnectionString)); var res = client.CreateIndex(req); }
public Boolean CreateIndex(String index, String type) { CreateIndexRequest createRequest = new CreateIndexRequest(index); createRequest.Mappings = new Mappings(); ITypeMapping typeMapping = new TypeMapping(); createRequest.Mappings.Add(type, typeMapping); var createIndexResponse = _elasticClient.CreateIndex(createRequest); return(createIndexResponse.IsValid); }
/// <summary>Snippet for CreateIndex</summary> public void CreateIndex_RequestObject() { // Snippet: CreateIndex(CreateIndexRequest,CallSettings) // Create client FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.Create(); // Initialize request argument(s) CreateIndexRequest request = new CreateIndexRequest { ParentAsParentName = new ParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]"), Index = new Index(), }; // Make the request Operation response = firestoreAdminClient.CreateIndex(request); // End snippet }
/// <summary> /// 本接口用于创建索引 /// </summary> /// <param name="req"><see cref="CreateIndexRequest"/></param> /// <returns><see cref="CreateIndexResponse"/></returns> public CreateIndexResponse CreateIndexSync(CreateIndexRequest req) { JsonResponseModel <CreateIndexResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "CreateIndex"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateIndexResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
public async Task CreateIndexAsync_RequestObject() { // Snippet: CreateIndexAsync(CreateIndexRequest,CallSettings) // Create client FirestoreAdminClient firestoreAdminClient = await FirestoreAdminClient.CreateAsync(); // Initialize request argument(s) CreateIndexRequest request = new CreateIndexRequest { Parent = new DatabaseName("[PROJECT]", "[DATABASE]").ToString(), Index = new Index(), }; // Make the request Operation response = await firestoreAdminClient.CreateIndexAsync(request); // End snippet }
private async Task VerifyIndexExists() { var exists = await Client.IndexExistsAsync(_config.IndexName); if (!exists.Exists) { var settings = new IndexSettings(); settings.NumberOfReplicas = 0; settings.NumberOfShards = 5; var createRequest = new CreateIndexRequest(new IndexName { Name = _config.IndexName, Cluster = "fFGNSMh" }); createRequest.Settings = settings; await Client.CreateIndexAsync(createRequest); } }
/// <summary>Snippet for CreateIndexAsync</summary> public async Task CreateIndexAsync_RequestObject() { // Snippet: CreateIndexAsync(CreateIndexRequest,CallSettings) // Additional: CreateIndexAsync(CreateIndexRequest,CancellationToken) // Create client FirestoreAdminClient firestoreAdminClient = await FirestoreAdminClient.CreateAsync(); // Initialize request argument(s) CreateIndexRequest request = new CreateIndexRequest { ParentAsParentName = new ParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]"), Index = new Index(), }; // Make the request Operation response = await firestoreAdminClient.CreateIndexAsync(request); // End snippet }
public Boolean ExistIndexAndCreateIndex(String index, String type) { // https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html if (_elasticClient.IndexExists(index).Exists == false) { CreateIndexRequest createRequest = new CreateIndexRequest(index); createRequest.Mappings = new Mappings(); ITypeMapping typeMapping = new TypeMapping(); createRequest.Mappings.Add(type, typeMapping); var createIndexResponse = _elasticClient.CreateIndex(createRequest); return(createIndexResponse.IsValid); } return(true); }
[AutomaticRetry(Attempts = BackgroundJobsConstants.NumberOfRetries)] //configure hangfire to retry on failure public void CreateIndex(CreateIndexRequest model, PerformContext context) { string cachedManagementInformation; if (m_MemoryCache.TryGetValue <string>(CacheKeys.ManagementInformationKey, out cachedManagementInformation)) { m_Manager.ManagementInformationPath = cachedManagementInformation; } var indexId = m_Manager.CreateIndex(model.SourcePath, model.FileExtensions); if (context != null) { m_MemoryCache.Set(context.BackgroundJob.Id, indexId); } else { m_Logger.Debug($"hangfire.io didn't inject PerformContext instance, didn't save indexId into memory cache "); } }
public void CreateIndex2() { Mock <FirestoreAdmin.FirestoreAdminClient> mockGrpcClient = new Mock <FirestoreAdmin.FirestoreAdminClient>(MockBehavior.Strict); CreateIndexRequest request = new CreateIndexRequest { ParentAsParentName = new ParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]"), Index = new Index(), }; Operation expectedResponse = new Operation { Name = "name3373707", Done = true, }; mockGrpcClient.Setup(x => x.CreateIndex(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); FirestoreAdminClient client = new FirestoreAdminClientImpl(mockGrpcClient.Object, null); Operation response = client.CreateIndex(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// Create a new index on the table identified by tableNameOrId. /// </summary> /// <param name="request"></param> /// <returns></returns> public CreateIndexResponse CreateIndex(CreateIndexRequest request) { var uri = new Uri(GetEndPoint(NoSQLServices.Tables, this.Region)); var httpRequestHeaderParam = new HttpRequestHeaderParam() { OpcRetryToken = request.OpcRetryToken, OpcRequestId = request.OpcRequestId }; using (var webResponse = this.RestClient.Post(uri, request.CreateIndexDetails, httpRequestHeaderParam)) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = reader.ReadToEnd(); return(new CreateIndexResponse() { OpcRequestId = webResponse.Headers.Get("opc-request-id"), OpcWorkRequestId = webResponse.Headers.Get("opc-work-request-id") }); } }
public async Task CreateIndexAsync() { Mock <FirestoreAdmin.FirestoreAdminClient> mockGrpcClient = new Mock <FirestoreAdmin.FirestoreAdminClient>(MockBehavior.Strict); CreateIndexRequest expectedRequest = new CreateIndexRequest { ParentAsParentName = new ParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]"), Index = new Index(), }; Operation expectedResponse = new Operation { Name = "name3373707", Done = true, }; mockGrpcClient.Setup(x => x.CreateIndexAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Operation>(Task.FromResult(expectedResponse), null, null, null, null)); FirestoreAdminClient client = new FirestoreAdminClientImpl(mockGrpcClient.Object, null); ParentName parent = new ParentName("[PROJECT]", "[DATABASE]", "[COLLECTION_ID]"); Index index = new Index(); Operation response = await client.CreateIndexAsync(parent, index); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
protected override void ProcessRecord() { base.ProcessRecord(); CreateIndexRequest request; try { request = new CreateIndexRequest { TableNameOrId = TableNameOrId, CreateIndexDetails = CreateIndexDetails, OpcRetryToken = OpcRetryToken, OpcRequestId = OpcRequestId }; response = client.CreateIndex(request).GetAwaiter().GetResult(); WriteOutput(response, CreateWorkRequestObject(response.OpcWorkRequestId)); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Creates the specified index. /// A newly created index's initial state is `CREATING`. On completion of the /// returned [google.longrunning.Operation][google.longrunning.Operation], the state will be `READY`. /// If the index already exists, the call will return an `ALREADY_EXISTS` /// status. /// /// During creation, the process could result in an error, in which case the /// index will move to the `ERROR` state. The process can be recovered by /// fixing the data that caused the error, removing the index with /// [delete][google.firestore.admin.v1beta1.FirestoreAdmin.DeleteIndex], then re-creating the index with /// [create][google.firestore.admin.v1beta1.FirestoreAdmin.CreateIndex]. /// /// Indexes with a single field cannot be created. /// </summary> /// <param name="request"> /// The request object containing all of the parameters for the API call. /// </param> /// <param name="callSettings"> /// If not null, applies overrides to this RPC call. /// </param> /// <returns> /// The RPC response. /// </returns> public virtual Operation CreateIndex( CreateIndexRequest request, CallSettings callSettings = null) { throw new NotImplementedException(); }
// Partial modifier methods contain '_' to ensure no name conflicts with RPC methods. partial void Modify_CreateIndexRequest(ref CreateIndexRequest request, ref CallSettings settings);
/// <summary> /// Creates the index. /// </summary> /// <param name="documentType">Type of the document.</param> /// <param name="deleteIfExists">if set to <c>true</c> [delete if exists].</param> public override void CreateIndex(Type documentType, bool deleteIfExists = true) { var indexName = documentType.Name.ToLower(); object instance = Activator.CreateInstance(documentType); // check if index already exists var existsResponse = _client.IndexExists(indexName); if (existsResponse.Exists) { if (deleteIfExists) { this.DeleteIndex(documentType); } else { return; } } // make sure this is an index document if (instance is IndexModelBase) { // create a new index request var createIndexRequest = new CreateIndexRequest(indexName); createIndexRequest.Mappings = new Mappings(); createIndexRequest.Settings = new IndexSettings(); createIndexRequest.Settings.NumberOfShards = GetAttributeValue("ShardCount").AsInteger(); var typeMapping = new TypeMapping(); typeMapping.Dynamic = DynamicMapping.Allow; typeMapping.Properties = new Properties(); createIndexRequest.Mappings.Add(indexName, typeMapping); var model = (IndexModelBase)instance; // get properties from the model and add them to the index (hint: attributes will be added dynamically as the documents are loaded) var modelProperties = documentType.GetProperties(); foreach (var property in modelProperties) { var indexAttributes = property.GetCustomAttributes(false); var indexAttribute = property.GetCustomAttributes(typeof(RockIndexField), false); if (indexAttribute.Length > 0) { var attribute = (RockIndexField)indexAttribute[0]; var propertyName = Char.ToLowerInvariant(property.Name[0]) + property.Name.Substring(1); // rewrite non-string index option (would be nice if they made the enums match up...) NonStringIndexOption nsIndexOption = NonStringIndexOption.NotAnalyzed; if (attribute.Type != IndexFieldType.String) { if (attribute.Index == IndexType.NotIndexed) { nsIndexOption = NonStringIndexOption.No; } } switch (attribute.Type) { case IndexFieldType.Boolean: { typeMapping.Properties.Add(propertyName, new BooleanProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } case IndexFieldType.Date: { typeMapping.Properties.Add(propertyName, new DateProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } case IndexFieldType.Number: { typeMapping.Properties.Add(propertyName, new NumberProperty() { Name = propertyName, Boost = attribute.Boost, Index = nsIndexOption }); break; } default: { var stringProperty = new StringProperty(); stringProperty.Name = propertyName; stringProperty.Boost = attribute.Boost; stringProperty.Index = (FieldIndexOption)attribute.Index; if (!string.IsNullOrWhiteSpace(attribute.Analyzer)) { stringProperty.Analyzer = attribute.Analyzer; } typeMapping.Properties.Add(propertyName, stringProperty); break; } } } } var response = _client.CreateIndex(createIndexRequest); } }
public async Task Test_DeleteIndex_Expect_Success() { using var client = m_TestServer.CreateClient(); var newPath = WebTestHelper.GetPathToTestData("Meta"); var configureModel = new { managementInformationPath = newPath }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json")) using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload)) { } var createIndexModel = new CreateIndexRequest() { SourcePath = WebTestHelper.GetPathToTestData("01_ToIndex"), FileExtensions = new[] { ".txt" } }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json")) using (_ = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload)) { } //TODO can be optimized with API method to get information if background job still running ICodeSearcherIndex[] indexesModel; int count = 0; do { using (var response = await client.GetAsync(APIRoutes.IndexListRoute)) { var responsePayload = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings(); settings.Converters.Add(Factory.Get().GetCodeSearcherIndexJsonConverter()); indexesModel = JsonConvert.DeserializeObject <ICodeSearcherIndex[]>(responsePayload, settings); Assert.That(indexesModel, Is.Not.Null); } await Task.Delay(250); //timeout Assert.That(count++, Is.LessThan(100)); } while (indexesModel.Length < 1); var deleteRequestModel = new DeleteIndexRequest { IndexID = indexesModel[0].ID }; // simplified API client.DeleteAsync doesn't allow to set content var deleteRequest = new HttpRequestMessage { Method = HttpMethod.Delete, RequestUri = new Uri(client.BaseAddress, APIRoutes.CreateIndexRoute), Content = new StringContent(JsonConvert.SerializeObject(deleteRequestModel), Encoding.UTF8, "application/json") }; using (var response = await client.SendAsync(deleteRequest)) { response.EnsureSuccessStatusCode(); var responsePayload = await response.Content.ReadAsStringAsync(); var deleteModel = JsonConvert.DeserializeObject <DeleteIndexResponse>(responsePayload); Assert.That(deleteModel, Is.Not.Null); Assert.That(deleteModel.Succeeded, Is.True); } }
public async Task Test_SearchInIndex_Expect_Success() { using var client = m_TestServer.CreateClient(); var newPath = WebTestHelper.GetPathToTestData("Meta"); var configureModel = new { managementInformationPath = newPath }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json")) using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload)) { } var createIndexModel = new CreateIndexRequest() { SourcePath = WebTestHelper.GetPathToTestData("01_ToIndex"), FileExtensions = new[] { ".txt" } }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json")) using (_ = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload)) { } ICodeSearcherIndex[] indexesModel; int count = 0; do { using (var response = await client.GetAsync(APIRoutes.IndexListRoute)) { var responsePayload = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings(); settings.Converters.Add(Factory.Get().GetCodeSearcherIndexJsonConverter()); indexesModel = JsonConvert.DeserializeObject <ICodeSearcherIndex[]>(responsePayload, settings); Assert.That(indexesModel, Is.Not.Null); } await Task.Delay(250); //timeout Assert.That(count++, Is.LessThan(100)); } while (indexesModel.Length < 1); var searchModel = new SearchIndexRequest() { IndexID = indexesModel[0].ID, SearchWord = "erat" }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(searchModel), Encoding.UTF8, "application/json")) { var request = new HttpRequestMessage { Method = HttpMethod.Post, Content = requestPayload, RequestUri = new Uri(client.BaseAddress, APIRoutes.SearchInIndexRoute) }; using (var response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); var responsePayload = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings(); settings.Converters.Add(Factory.Get().GetDetailedResultJsonConverter()); settings.Converters.Add(Factory.Get().GetFindingsInFileJsonConverter()); var searchIndex = JsonConvert.DeserializeObject <SearchIndexResponse>(responsePayload, settings); } } }
public Task <IResponse> CreateIndexAsync(CreateIndexRequest request) => this.SendRequestAsync( new HttpRequestMessageBuilder(HttpMethod.Post, $"/logstores/{request.LogstoreName}/index") .Content(request) .Serialize(SerializeType.Json), project: request.ProjectName);
public void FSCreateIndex() { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Creating a Index ::\n"); var index = new Index(); while (true) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Field Name (blank when finished): "); string fieldName = Console.ReadLine(); if (fieldName != "") { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Mode (ASCENDING/DESCENDING) [ASCENDING]: "); string fieldMode = Console.ReadLine(); IndexField.Types.Mode indexFieldMode = IndexField.Types.Mode.Ascending; if (fieldMode == "" || fieldMode == "ASCENDING") { indexFieldMode = IndexField.Types.Mode.Ascending; } else if (fieldMode == "DESCENDING") { indexFieldMode = IndexField.Types.Mode.Descending; } else if (fieldMode != "ASCENDING" && fieldMode != "DESCENDING") { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nUnrecognized Mode - Choosing ASCENDING"); indexFieldMode = IndexField.Types.Mode.Ascending; } var indexField = new IndexField(); indexField.FieldPath = fieldName; indexField.Mode = indexFieldMode; index.Fields.Add(indexField); } else { var createIndexRequest = new CreateIndexRequest(); createIndexRequest.Parent = Parent; index.CollectionId = BaseCollectionId; createIndexRequest.Index = index; try { Operation operation = FsAdminClient.CreateIndex(createIndexRequest); } catch (Grpc.Core.RpcException e) { Grpc.Core.Status stat = e.Status; if (stat.StatusCode == Grpc.Core.StatusCode.AlreadyExists) { Console.WriteLine("\nIndex already exists."); } Console.WriteLine(stat.Detail); } catch (Exception e) { FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nException caught\n" + e.Message); } break; } } FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully created new index!\n"); }