英文:
ElasticSearch .NET DeleteByQueryAsync on Elastic.Clients.Elasticsearch 8.9.1
问题
我正在将我的.NET项目从NEST 6.8.8更新到Elastic.Clients.Elasticsearch 8.9.1。
我有一个方法,应该只删除索引中早于给定日期的文档。在NEST版本上它可以工作,但在Elastic.Clients.ElasticSearch上不行。
在NEST版本上,这段代码可以工作:
var result = await _client.DeleteByQueryAsync
但在Elastic.Client.ElasticSearch中,这会导致"无法推断委托类型"的错误。
我有一个使用SearchAsync方法的方法,类似的语法在那里可以工作。
我尝试找到如何在Elastic.Clients.ElasticSearch中使用DeleteByQuery的示例,但没有找到。
谢谢你的帮助!
英文:
I am updating my .NET project from NEST 6.8.8 to Elastic.Clients.Elasticsearch 8.9.1
I have method that should just delete documents from index that are older than given date. On the NEST version it works but not on the Elastic.Clients.ElasticSearch
On the NEST version this code did work
var result = await _client.DeleteByQueryAsync<object>( d => d
.Index(index)
.Query(q => q.DateRange(r => r
.Field(field)
.LessThanOrEquals(date)
)));
But in the Elastic.Client.ElasticSearch this gives "The delegate type could not be inferred" error.
I have method that uses SearchAsync method and similar syntax works with that.
I have tried to find examples how to use DeleteByQuery with Elastic.Clients.ElasticSearch but haven't found any.
Thanks for your help!
答案1
得分: 1
我的同事找到了正确的格式:
DeleteByQueryResponse result = await _client.DeleteByQueryAsync<object>(index,
d => d
.Query(q => q
.Range(r => r
.DateRange(dr => dr
.Field(field)
.Lt(date)))));
请注意,这是一段C#代码,用于执行删除查询操作。
英文:
My colleague found correct format for this
DeleteByQueryResponse result = await _client.DeleteByQueryAsync<object>(index,
d => d
.Query(q => q
.Range(r => r
.DateRange(dr => dr
.Field(field)
.Lt(date)))));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论