Using fluent lambda expressions with a scroll search request

I’ve been unable to use fluent lambda expressions when searching with a scroll. I have the code working using direct creations of the request objects:

public async Task<List<int>> GetAllElasticIds()
{
   var ids = new List<int>();

    var searchResponse = await this.elasticsearchClient.SearchAsync<ElasticModel>(s => s
        .Index(“index1”)
        .Query(q => q
            .MatchAll(_ => { }))
        .Size(5)
        .Scroll(“1m”)
        .Source(new SourceConfig(new SourceFilter
        {
            Includes = "id"
        })));
    
    ids.AddRange(searchResponse.Documents.Select(d => d.Id));

    var scrollId = searchResponse.ScrollId;
    var docCount = searchResponse.Documents.Count;
    
    while (scrollId is not null && docCount != 0)
    {
        var scrollResponse = await this.elasticsearchClient.ScrollAsync<ElasticModel>(new ScrollRequest{ScrollId = scrollId, Scroll = ScrollTime});

        ids.AddRange(scrollResponse.Documents.Select(d => d.Id));
        
        scrollId = scrollResponse.ScrollId;
        docCount = scrollResponse.Documents.Count;
    }
    
    if (scrollId is not null)
    {
           var clearScrollResponse = await this.elasticsearchClient.ClearScrollAsync(new ClearScrollRequest {ScrollId = scrollId});
    }
}

Is there a way I can fluently create the SourceConfig / SourceFilter / ScrollRequest / ClearScrollRequest objects within the request ?

Elasticsearch package version: 8.18

@TSlump It should be possible when using client 8.19.x. I decided to backport all 9.0+ improvements to 8.19. This also includes a lot of usability fixes to the fluent syntax. Please carefully check the 9.0 breaking changes since they apply to 8.18 → 8.19 as well.

1 Like

Ah awesome, will use the 8.19 package instead then. Thank you !