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

Allow serializing requests independently from the transport #546

Open
patpatpat123 opened this issue Mar 29, 2023 · 2 comments
Open

Allow serializing requests independently from the transport #546

patpatpat123 opened this issue Mar 29, 2023 · 2 comments
Labels
Category: Enhancement New feature or request

Comments

@patpatpat123
Copy link

Description

Hello, Elastic java team,

I wanted to reach out to ask for a possible enhancement request, please.

This project proposes a very nice abstraction through its wrapper.

For instance, the BulkRequest:

List<Product> products = fetchProducts();

BulkRequest.Builder br = new BulkRequest.Builder();

for (Product product : products) {
    br.operations(op -> op           
        .index(idx -> idx            
            .index("products")       
            .id(product.getSku())
            .document(product)
        )
    );
}

Would it be possible to enhance this in order to get the http request payload directly, please?

Something like bulkRequest.getRequestBody() which would allow getting the request and its body, without executing, instead of BulkResponse result = esClient.bulk(br.build()); which would execute the request.

This would allow the possibility to enrich the content of the request, and most of all, to be able to just get the request body and send it with other http client, such as Okhttp, Netty, etc... without being coupled with the default RestClient of this repo.

@patpatpat123 patpatpat123 changed the title [Feature Request] possibility to get request body [Feature Request] possibility to get request body bulkRequest.getRequestBody() Mar 30, 2023
@swallez swallez changed the title [Feature Request] possibility to get request body bulkRequest.getRequestBody() Allow serializing requests independently from the transport Apr 3, 2023
@swallez swallez added the Category: Enhancement New feature or request label Apr 3, 2023
@swallez
Copy link
Member

swallez commented Apr 3, 2023

We generally want to avoid code that is specific for a particular request, as the need may actually apply to all of them.

Currently the serialization is handled within the Transport implementation. Bulk requests belong to a family of requests that are sent as nd-json (one json document per line). This is handled by RestClientTransport.writeNdJson() that you can copy in your code to use a different client.

A possible evolution is to extract this code in a separate class so that it can called not only by the transport class, but also any other application code. I've renamed the issue to reflect this.

@patpatpat123
Copy link
Author

patpatpat123 commented Apr 4, 2023

"A possible evolution is to extract this code in a separate class so that it can called not only by the transport class, but also any other application code."

-> this is what I intended to say. Thank you for the correction. Looking forward to seeing this in the future, many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants