当前位置: 首页>>代码示例>>C#>>正文


C# ElasticClient.IndexManyAsync方法代码示例

本文整理汇总了C#中Nest.ElasticClient.IndexManyAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient.IndexManyAsync方法的具体用法?C# ElasticClient.IndexManyAsync怎么用?C# ElasticClient.IndexManyAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nest.ElasticClient的用法示例。


在下文中一共展示了ElasticClient.IndexManyAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateAndIndex

 protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
 {
     var msgGenerator = new MessageGenerator();
     var tasks = new List<Task>();
     var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
     client.CreateIndex(indexName, c => c
         .NumberOfReplicas(0)
         .NumberOfShards(1)
         .Settings(s => s.Add("refresh_interval", "-1"))
         .AddMapping<Message>(p=>p.MapFromAttributes())
     );
     Interlocked.Exchange(ref NumSent, 0);
     foreach (var messages in partitionedMessages)
     {
         var t = client.IndexManyAsync(messages, indexName)
             .ContinueWith(tt =>
             {
                 Interlocked.Add(ref NumSent, bufferSize);
                 Console.WriteLine("Sent {0:0,0} messages to {1}, {2}", NumSent, indexName, tt.Result.Took);
             })
             ;
         tasks.Add(t);
     }
     Task.WaitAll(tasks.ToArray());
     client.UpdateSettings(u => u
         .Index(indexName)
         .RefreshInterval("1s")
     );
 }
开发者ID:rodrigopalhares,项目名称:NEST,代码行数:29,代码来源:Tester.cs

示例2: ReIndexBulk

 public async Task<IBulkResponse> ReIndexBulk(IEnumerable<BeerDto> beers, string index)
 {
     //string url = WebConfigurationManager.AppSettings["elasticsearch"];
     //var node = new Uri(url);
     var settings = new ConnectionSettings(_node, defaultIndex: index);
     var client = new ElasticClient(settings);
     await client.MapAsync<BeerDto>(d => d.Properties(p => p.String(s => s.Name(n => n.Name).Analyzer("autocomplete"))));
     return await client.IndexManyAsync(beers);
 }
开发者ID:johnfredrik,项目名称:MicrobrewitApi,代码行数:9,代码来源:BeerElasticsearch.cs

示例3: GenerateAndIndex

 protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
 {
     var msgGenerator = new MessageGenerator();
     var tasks = new List<Task>();
     var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
     Interlocked.Exchange(ref NumSent, 0);
     foreach (var messages in partitionedMessages)
     {
         var t = client.IndexManyAsync(messages, indexName)
             .ContinueWith(tt =>
             {
                 Interlocked.Add(ref NumSent, bufferSize);
                 Console.WriteLine("Sent {0:0,0} messages to {1}, {2}", NumSent, indexName, tt.Result.Took);
             })
             ;
         tasks.Add(t);
     }
     Task.WaitAll(tasks.ToArray());
 }
开发者ID:v-kovrigin,项目名称:NEST,代码行数:19,代码来源:Tester.cs

示例4: GenerateAndIndex

        protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
        {
            // refresh = false is default on elasticsearch's side.
            var bulkParms = new SimpleBulkParameters() { Refresh = false };

            var msgGenerator = new MessageGenerator();
            var tasks = new List<Task>();
            var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
            Interlocked.Exchange(ref NumSent, 0);
            foreach (var messages in partitionedMessages)
            {
                var t = client.IndexManyAsync(messages, indexName, bulkParms);
                tasks.Add(t);

                Interlocked.Add(ref NumSent, bufferSize);
                if (NumSent % 10000 == 0)
                {
                    Console.WriteLine("Sent {0:0,0} messages to {1}", NumSent, indexName);
                }
            }
            Task.WaitAll(tasks.ToArray());
        }
开发者ID:JesperSchultz,项目名称:NEST,代码行数:22,代码来源:Tester.cs

示例5: Main

        /// <summary>
        /// Depends on hn_full_11-07-2010.xml which you can download from: 
        /// http://api.ihackernews.com/torrents/hn_full_11-07-2010.zip.torrent
        /// 
        /// When run from debug make sure to change the default debug arguments.
        /// <param name="args">Full filepath to hn_full_11-07-2010.xml</param>
        static void Main(string[] args)
        {
            var filePath = args.First();
            var elasticSettings = new ConnectionSettings("127.0.0.1.", 9200)
                                        .SetDefaultIndex("mpdreamz")
                                        .SetMaximumAsyncConnections(50);
            var client = new ElasticClient(elasticSettings);
            ConnectionStatus connectionStatus;
            if (!client.TryConnect(out connectionStatus))
            {
                Console.Error.WriteLine("Could not connect to {0}:\r\n{1}",
                    elasticSettings.Host, connectionStatus.Error.OriginalException.Message);
                Console.Read();
                return;
            }

            var reader = new XmlTextReader(filePath);
            Post post = new Post();
            PostMetaData meta = new PostMetaData();

            int processed = 0, dropped = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var postQueue = new List<Post>();
            try
            {
                while (reader.Read())
                {
                    var name = reader.Name;

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (name == "HackerNews")
                            continue;

                        if (name == "ID")
                            post.Id = reader.ReadElementContentAsInt();

                        else if (name == "ParentID")
                            post.ParentId = reader.ReadElementContentAsInt();
                        else if (name == "Url")
                            post.Url = reader.ReadElementContentAsString();
                        else if (name == "Title")
                            post.Title = reader.ReadElementContentAsString();
                        else if (name == "Text")
                            post.Text = reader.ReadElementContentAsString();
                        else if (name == "Username")
                            meta.Username = reader.ReadElementContentAsString();
                        else if (name == "Points")
                            meta.Points = reader.ReadElementContentAsInt();
                        else if (name == "Type")
                            meta.Type = reader.ReadElementContentAsInt();
                        else if (name == "Timestamp")
                            meta.Created = reader.ReadElementContentAsDateTime();
                        else if (name == "CommentCount")
                            meta.CommentsCount = reader.ReadElementContentAsInt();
                    }

                    if (reader.NodeType == XmlNodeType.EndElement
                        && name == "row")
                    {
                        post.Meta = meta;
                        postQueue.Add(post);
                        if (postQueue.Count() == 1000)
                        {
                            var t = client.IndexManyAsync(postQueue);
                            t.ContinueWith(c =>
                            {
                                var result = c.Result;
                                if (!result.Success)
                                    dropped++;
                            });
                            processed += postQueue.Count();
                            postQueue = new List<Post>();

                        }
                        Console.Write("\rProcessed:{0}, Dropped:{2} in {1}", processed, sw.Elapsed, dropped);

                        post = new Post();
                        meta = new PostMetaData();
                    }
                }
                if (postQueue.Count() > 0)
                {
                    var task = client.IndexManyAsync(postQueue).ContinueWith(t =>
                    {
                        var c = t.Result;
                        if (!c.Success)
                            Interlocked.Increment(ref dropped);
                        return t;
                    });
                    Interlocked.Add(ref processed, postQueue.Count());
                    postQueue = new List<Post>();

//.........这里部分代码省略.........
开发者ID:aqbjteddy,项目名称:NEST,代码行数:101,代码来源:Program.cs


注:本文中的Nest.ElasticClient.IndexManyAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。