Esempio n. 1
0
        public bool DeleteAll()
        {
            var client = _EsClientProvider.GetClient(IndexName);
            var search = new DeleteByQueryDescriptor <TestLog>().Index(IndexName);

            search = search.Query(p => p.MatchAll());
            var response = client.DeleteByQuery <TestLog>(p => search);

            return(response.IsValid);
        }
Esempio n. 2
0
        /// <summary>
        /// 删除指定城市的数据
        /// </summary>
        /// <param name="city"></param>
        /// <returns></returns>
        public bool DeleteByQuery(string city)
        {
            var client = _EsClientProvider.GetClient(IndexName);
            var musts  = new List <Func <QueryContainerDescriptor <Address>, QueryContainer> >();

            musts.Add(p => p.Term(m => m.Field(f => f.City).Value(city)));
            var search = new DeleteByQueryDescriptor <Address>().Index(IndexName);

            search = search.Query(p => p.Bool(m => m.Must(musts)));
            var response = client.DeleteByQuery <Address>(p => search);

            return(response.IsValid);
        }
Esempio n. 3
0
 /// <summary>生成按查询删除请求</summary>
 private IDeleteByQueryRequest UseDeleteQuery(DeleteByQueryDescriptor <TIndexType> descriptor, List <string> iiids)
 {
     descriptor.Type(this.IndexType);
     descriptor.Query(queryDescriptor => queryDescriptor
                      .Terms(e => e
                             .Field(f => f[MetadataConsts.IIId])
                             .Terms(iiids)
                             )
                      )
     .Refresh(true)
     ;
     return(descriptor);
 }
        public async Task Test_DeleteByQueryAsync()
        {
            using var scope = ServiceProvider.CreateScope();
            var resp    = scope.ServiceProvider.GetService <IEsRepository <StudentSample> >();
            var student = _students.First();
            await resp.InsertAsync(student);

            // 需要延迟一下
            await Task.Delay(1000);

            var descriptor = new DeleteByQueryDescriptor <StudentSample>();

            descriptor.Query(q => q
                             .Term(r => r
                                   .Field(f => f.StudentId)
                                   .Value(student.StudentId)));
            await resp.DeleteByQueryAsync(descriptor);

            var result = await resp.FindByIdAsync(student.StudentId);

            Assert.Null(result);
        }
Esempio n. 5
0
        public static DeleteByQueryDescriptor <T> FilteredOn <T>(this DeleteByQueryDescriptor <T> deleteDescriptor, Expression <Func <T, bool> > filterRule) where T : class
        {
            var binaryExpression = filterRule.Body as BinaryExpression;

            return(deleteDescriptor.Query(q => q.Filtered(fil => fil.Filter(f => GenerateFilterDescription <T>(binaryExpression)))));
        }
Esempio n. 6
0
 public static DeleteByQueryDescriptor <T> FilteredOn <T>(this DeleteByQueryDescriptor <T> deleteDescriptor, FilterContainer container) where T : class
 {
     return(deleteDescriptor.Query(q => q.Filtered(fil => fil.Filter(f => container))));
 }
Esempio n. 7
0
        public static DeleteByQueryDescriptor <T> FilterOn <T>(this DeleteByQueryDescriptor <T> deleteDescriptor, Expression <Func <T, bool> > filterRule) where T : class
        {
            var filterDescriptor = GenerateFilterDescription <T>(filterRule.Body);

            return(deleteDescriptor.Query(_ => filterDescriptor));
        }
Esempio n. 8
0
 public static DeleteByQueryDescriptor <T> FilterOn <T>(this DeleteByQueryDescriptor <T> deleteDescriptor, QueryContainer container) where T : class
 {
     return(deleteDescriptor.Query(q => container));
 }