Esempio n. 1
0
        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <param name="connection">数据库连接</param>
        protected Nest.IElasticClient GetClient()
        {
            var connection = _client?.GetClient();

            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            return(connection);
        }
Esempio n. 2
0
        public void Add(IEnumerable <TEntity> entities, string index, Expression <Func <TEntity, object> > expression, string typeName = null)
        {
            if (typeName == null)
            {
                typeName = typeof(TEntity).Name.ToLower();
            }
            var c = _client.GetClient();

            var column = Lambda.GetName(expression);

            var response = c.Bulk(bd => bd.CreateMany <TEntity>(entities, (b, t) => b.Index(index).Id(GetId(column, t)).Type(typeName)));

            ThrowCheckByResponse(response);
        }