索引时出现错误请求错误

时间:2015-04-09 05:28:43

标签: c# windows elasticsearch elmah nest

我已经下载并配置了ElasticSearch。当我尝试使用elasticsearch客户端索引一个实例,即Nest时,我得到了"远程服务器返回了一个错误:(400)Bad Request"错误。问题是什么?

static void Main(string[] args)
        {
                const string folderLocation = @"\\c:\elmah-exceptions\";
                var ElasticSearchServerURI = "http://localhost:9200";
                var defaultIndex = "Prod";
                var uri = new Uri(ElasticSearchServerURI);
                var connectionSettings = new ConnectionSettings(uri, defaultIndex).EnableTrace(true).ExposeRawResponse(true);
                var elasticClient = new ElasticClient(connectionSettings);

                var files = GetFiles(folderLocation);
                foreach (var file in files)
                {
                    var error = ParseFile(file);
                    if (error != null)
                    {
                        elasticClient.Index(error);//I get an error on this line
                    }
                }         
        }

public class Error
    {
        public string errorType { get; set; }
        public string message { get; set; }
        public string source { get; set; }
        public string errorArea { get; set; }

        public string queryString { get; set; }
        public string siteId { get; set; }
        public string model { get; set; }
        public string eolUserName { get; set; }
        public string name { get; set; }

        public string httpClientSrcIP { get; set; }
        public string errorTime { get; set; }
        public string sessionId { get; set; }
        public string httpSoapAction { get; set; }
        public string pathTranslated { get; set; }
        public string httpReferer { get; set; }

        public string sessionStartQueryString { get; set; }

        public string file { get; set; }
        public string host { get; set; }
    }

1 个答案:

答案 0 :(得分:3)

修复是默认索引应为小写。

static void Main(string[] args)
        {
                const string folderLocation = @"\\c:\elmah-exceptions\";
                var ElasticSearchServerURI = "http://localhost:9200";
                var defaultIndex = "prod";
                var uri = new Uri(ElasticSearchServerURI);
                var connectionSettings = new ConnectionSettings(uri, defaultIndex).EnableTrace(true).ExposeRawResponse(true);
                var elasticClient = new ElasticClient(connectionSettings);

                var files = GetFiles(folderLocation);
                foreach (var file in files)
                {
                    var error = ParseFile(file);
                    if (error != null)
                    {
                        elasticClient.Index(error);//I get an error on this line
                    }
                }         
        }

public class Error
    {
        public string errorType { get; set; }
        public string message { get; set; }
        public string source { get; set; }
        public string errorArea { get; set; }

        public string queryString { get; set; }
        public string siteId { get; set; }
        public string model { get; set; }
        public string eolUserName { get; set; }
        public string name { get; set; }

        public string httpClientSrcIP { get; set; }
        public string errorTime { get; set; }
        public string sessionId { get; set; }
        public string httpSoapAction { get; set; }
        public string pathTranslated { get; set; }
        public string httpReferer { get; set; }

        public string sessionStartQueryString { get; set; }

        public string file { get; set; }
        public string host { get; set; }
    }