ElasticSearch .NET DeleteByQueryAsync 在 Elastic.Clients.Elasticsearch 8.9.1 上的使用方法。

huangapple go评论110阅读模式
英文:

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(d => d
.Index(index)
.Query(q => q.DateRange(r => r
.Field(field)
.LessThanOrEquals(date)
)));

但在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&lt;object&gt;(index,
            d =&gt; d
                .Query(q =&gt; q
                    .Range(r =&gt; r
                        .DateRange(dr =&gt; dr
                            .Field(field)
                            .Lt(date)))));

huangapple
  • 本文由 发表于 2023年8月8日 20:44:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定

  • 开发者交流平台

    本页二维码