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


C# ElasticClient.IndexAsync方法代码示例

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


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

示例1: TestIndexTimeout

        public void TestIndexTimeout()
        {
            var timeout = 1;
            var s = new ConnectionSettings(Test.Default.Host, Test.Default.Port, timeout)
                        .SetDefaultIndex(Test.Default.DefaultIndex)
                        .SetMaximumAsyncConnections(Test.Default.MaximumAsyncConnections)
                        .UsePrettyResponses();

            var client = new ElasticClient(s);

            var newProject = new ElasticSearchProject
            {
                Name = "COBOLES", //COBOL ES client ?
            };
            var t = client.IndexAsync<ElasticSearchProject>(newProject);
            t.Wait(1000);
            var cs = t.Result;
            Assert.False(cs.Success);
            Assert.NotNull(cs.Error);
            Assert.NotNull(cs.Error.OriginalException);
            Trace.WriteLine(cs.Error.OriginalException);
            Assert.IsNotNullOrEmpty(cs.Error.ExceptionMessage);
            Assert.IsTrue(cs.Error.OriginalException is WebException);
            var we = cs.Error.OriginalException as WebException;
            Assert.IsTrue(cs.Error.ExceptionMessage.Contains("The request was canceled"));
            Assert.IsTrue(we.Status == WebExceptionStatus.RequestCanceled);
            Assert.True(t.IsCompleted, "task did not complete");
            Assert.False(t.IsFaulted, "task was faulted, wich means the exception did not cleanly pass to ConnectionStatus");
        }
开发者ID:Wigren,项目名称:NEST,代码行数:29,代码来源:AsyncTests.cs

示例2: Append

        /// <summary>
        /// Add a log event to the ElasticSearch Repo
        /// </summary>
        /// <param name="loggingEvent"></param>
        protected override void Append(Core.LoggingEvent loggingEvent)
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                var exception = new InvalidOperationException("Connection string not present.");
                ErrorHandler.Error("Connection string not included in appender.", exception, ErrorCode.GenericFailure);

                return;
            }

            client = new ElasticClient(ConnectionBuilder.BuildElsticSearchConnection(ConnectionString));
            
            LogEvent logEvent = new LogEvent();
            
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }

            logEvent.LoggerName = loggingEvent.LoggerName;
            logEvent.Domain = loggingEvent.Domain;
            logEvent.Identity = loggingEvent.Identity;
            logEvent.ThreadName = loggingEvent.ThreadName;
            logEvent.UserName = loggingEvent.UserName;
            logEvent.MessageObject = loggingEvent.MessageObject == null ? "" : loggingEvent.MessageObject.ToString();
            logEvent.TimeStamp = loggingEvent.TimeStamp;
            logEvent.Exception = loggingEvent.ExceptionObject == null ? "" : loggingEvent.MessageObject.ToString();
            logEvent.Message = loggingEvent.RenderedMessage;
            logEvent.Fix = loggingEvent.Fix.ToString();
            logEvent.HostName = Environment.MachineName;

            if (loggingEvent.Level != null)
            {
                logEvent.Level = loggingEvent.Level.DisplayName;
            }

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.ClassName = loggingEvent.LocationInformation.ClassName;
                logEvent.FileName = loggingEvent.LocationInformation.FileName;
                logEvent.LineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.FullInfo = loggingEvent.LocationInformation.FullInfo;
                logEvent.MethodName = loggingEvent.LocationInformation.MethodName;
            }

            logEvent.Properties = loggingEvent.Properties.GetKeys().ToDictionary(key => key, key => logEvent.Properties[key].ToString());

            if (client.IsValid)
            {
                client.IndexAsync(logEvent);    
            }
            else
            {
                var exception = new InvalidOperationException("Connection to ElasticSearch is invalid.");
                ErrorHandler.Error("Invalid connection to ElasticSearch", exception, ErrorCode.GenericFailure);

                return;
            }
        }
开发者ID:nemec,项目名称:log4net.ElasticSearch,代码行数:63,代码来源:ElasticSearchAppender.cs

示例3: Append

        /// <summary>
        /// Add a log event to the ElasticSearch Repo
        /// </summary>
        /// <param name="loggingEvent"></param>
        protected override void Append(Core.LoggingEvent loggingEvent)
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                var exception = new InvalidOperationException("Connection string not present.");
                ErrorHandler.Error("Connection string not included in appender.", exception, ErrorCode.GenericFailure);

                return;
            }
            var settings = ConnectionBuilder.BuildElsticSearchConnection(ConnectionString);
            client = new ElasticClient(settings);
            var logEvent = CreateLogEvent(loggingEvent);
            try
            {
                client.IndexAsync(logEvent, settings.DefaultIndex, "LogEvent");
            }
            catch (InvalidOperationException ex)
            {
                ErrorHandler.Error("Invalid connection to ElasticSearch", ex, ErrorCode.GenericFailure);
            }
        }
开发者ID:kjersti,项目名称:log4net.ElasticSearch,代码行数:25,代码来源:ElasticSearchAppender.cs

示例4: 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)
                        {
                            client.IndexAsync<Post>(postQueue, (c) =>
                            {
                                if (!c.Success)
                                    dropped++;
                            });

                            postQueue = new List<Post>();
                            processed++;
                        }

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

                        post = new Post();
                        meta = new PostMetaData();
                    }

                }
                sw.Stop();
                Console.WriteLine("\nDone! {0}", sw.Elapsed);
            }
            catch (Exception e)
            {

            }
        }
开发者ID:rudimk,项目名称:NEST,代码行数:98,代码来源:Program.cs


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