コード例 #1
0
        public ResultWrapper <T> BulkAddOrUpdate <T>(string index, string type, IEnumerable <T> body, Func <T, string> getId) where T : class
        {
            var dynamicBody = new List <object>();

            foreach (var item in body)
            {
                var id = getId(item);
                dynamicBody.Add(new {
                    index = new {
                        _id = id
                    }
                });
                dynamicBody.Add(item);
            }



            var response = _clusterClient.BulkPut <T>(index, type, new PostData <object>(dynamicBody));

            return(new ResultWrapper <T>
            {
                ErrorMessage = response.ServerError.Error.Reason == null ? null : response.ServerError.Error.Reason,
                IsError = response.HttpStatusCode != (int)HttpStatusCode.OK,
                StatusCode = response.HttpStatusCode
            });
        }