Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchResponse and ScrollResponse do not have a common base class #8353

Open
braveyp opened this issue Sep 19, 2024 · 2 comments
Open

SearchResponse and ScrollResponse do not have a common base class #8353

braveyp opened this issue Sep 19, 2024 · 2 comments
Labels

Comments

@braveyp
Copy link

braveyp commented Sep 19, 2024

Elastic.Clients.Elasticsearch version: 8.15.6

Elasticsearch version: 8.15.0

.NET runtime version: 4.8

Operating system version: Windows 11

Description of the problem including expected versus actual behavior:

SearchResponse and ScrollResponse do not have a common base class so the simple bulk operation of making an initial Search and then iterating through the results with subsequent Scroll requests requires extra complexity in the client application - you either have to write two near identical functions (they differ by the type of the response input) to process the responses or create two wrapper classes to give a common interface and write one handler.

@flobernd
Copy link
Member

flobernd commented Sep 23, 2024

Hi @braveyp,

these responses are generated from our specification. The specification closely maps the server-side of things and there simply is no common base class.

We could potentially introduce a helper (similar to what is planned for PIT #5149) to simplify usage.

Couldn't you just simply use a (local) function to which you pass all the required properties?

public void DoSomethingWithMyDocuments<TDocument>(IEnumerable<TDocument> documents, long took)
{
    // ...
}

DoSomethingWithMyDocuments(searchResponse.Documents, searchResponse.Took);
// ...
DoSomethingWithMyDocuments(scrollResponse.Documents, scrollResponse.Took);

@braveyp
Copy link
Author

braveyp commented Sep 23, 2024

I did end up doing something along those lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants