以下代码使用Nest库，请用Elastic.Clients.Elasticsearch替换Nest的c#代码要怎么写呢？

        public IElasticClient CreateConnection(string index = null)
        {
            var sparePartsIndex = _configuration.SparePartsIndex;
            if (index != null)
            {
                sparePartsIndex = index;
            }
            var settings = new ConnectionSettings(new Uri(_configuration.ElasticSearchUrl));
            settings.MapDefaultTypeIndices(s => s.
              Add(typeof(SparePartEntity), sparePartsIndex)
              .Add(typeof(OperationLogEntity), sparePartsIndex)
              .Add(typeof(CatalogueData), sparePartsIndex)
              .Add(typeof(StatisticsService), sparePartsIndex)
              .Add(typeof(ImageEntity), sparePartsIndex)
              .Add(typeof(MetadataEntity), sparePartsIndex)
              .Add(typeof(SparePartImageSet), sparePartsIndex));
            settings.MapDefaultTypeNames(fd => fd.Add(typeof(SparePartEntity), "sparepartentities")
              .Add(typeof(MetadataEntity), "metadataentities")
              );
            settings.SetMaximumAsyncConnections(20);
            settings.SetTimeout(int.MaxValue);
#if DEBUG
            //settings.SetProxy(new Uri("http://webgateway.eu.schindler.com:3128/"), "GLOBAL\\bachmam2", "Sk@teboard");
            //settings.SetProxy(new Uri("http://localhost:8888"), null, null);
            settings.EnableTrace();
            settings.UsePrettyResponses();
#endif

            return new ElasticClient(settings);
        }

            private async Task RemoveUnusedMetadataAsync(OperationLogEntity logEntity)
    {
      foreach (var kgInfo in KgMetadataProvider.GetKgInfos())
      {
        //logEntity.Add(LogLevel.Debug, "remove nuller metadata");
          var facets = await this.SparePartStore.GetFacetsAsyncFromAttributeId(kgInfo.Id);
        //logEntity.Add(LogLevel.Debug, "total facets: " + facets.SelectMany(f => f.FilterCounts).Count());
        var metadataEntities = await this.GetAsync(null, kgInfo.Id, null);
        //logEntity.Add(LogLevel.Debug, "metadata entities: " + metadataEntities.Count());
        var toDelete = metadataEntities.Where(metadataEntity => facets.Where(f => f.FilterType == metadataEntity.FilterType)
                                                                      .SelectMany(f => f.FilterCounts)
                                                                      .All(f => !metadataEntity.Id.Contains(f.Id))).ToList();
        if (toDelete.Any())
        {
          logEntity.Add(LogLevel.Debug, "nuller metadata to delete: " + toDelete.Count());
          await _client.DeleteManyAsync(toDelete);
        }
        else
        {
          logEntity.Add(LogLevel.Debug, "no nuller metadata found");
        }
      }

    }

        public async Task<IEnumerable<MetadataEntity>> GetAsync(string languageKey, string kgId, long? revision)
    {
      var entities = await _client.SearchAsync<MetadataEntity>(sd =>
      {

        sd = sd.Filter(fd =>
        {
          var filterContainer = fd.Term(m => m.Kg, kgId);
          if (languageKey != null)
          {
            filterContainer = filterContainer && fd.Term(m => m.LanguageKey, languageKey);
          }
          return filterContainer;
        });

        sd = sd.Size(100000)
          .SortAscending(m => m.Name);
        return sd;
      });
      return entities.Documents;
    }

    private IDeleteResponse Clear()
    {
      return _client.DeleteByQuery<MetadataEntity>(dbd => dbd.MatchAll());
    }