Skip to content

BulkOperation and IndexRequest have different behaviour with same custom JsonpSerializer serializer #172

Open

Description

@fmarazita

Hi,

It seems that BulkOperation and IndexRequest with same tDocumentSerialization have different behaviour.
Elastic version: 7.16.3

I created a test with the same upsert operation, with and without using bulk operation. The business logic is very simple:

public IndexRequest<B> indexRequest(String index, B bean) {
        CustomSerializer<D, B, K> serialize = new CustomSerializer<>(...); //-> where CustomSerializer implements JsonpSerializer<B>
       return new IndexRequest.Builder<B>()
                    .index(index)
                    .id(createElasticId(bean))
                    .tDocumentSerializer(serialize)
                    .document(bean)
                    .build();
    }
public BulkOperation bulkIndexRequest(String index, B bean){
     CustomSerializer<D, B, K> serialize = new CustomSerializer<>(...); //-> where CustomSerializer implements JsonpSerializer<B>
    return new BulkOperation.Builder()
            .index(new IndexOperation.Builder<B>()
                    .index(index)
                    .id(createElasticId(bean))
                    .tDocumentSerializer(serialize)
                    .document(bean)
                    .build())
            .build();

}

public BulkResponse sendBulkRequest(List<BulkOperation> indexRequestList) {
   return restClient.bulk(new BulkRequest.Builder().operations(indexRequestList).build()) //--> restClient is a ElasticsearchClient instance
}

public IndexResponse sendIndexRequest(IndexRequest<B> indexRequest) {
    return restClient.index(indexRequest); //--> restClient is a ElasticsearchClient instance
}`

In the first case the serialization works, the client sent the serialized document to elastic and I am happy.
The second one failed, No serializer found for class:

Caused by: jakarta.json.JsonException: Jackson exception at co.elastic.clients.json.jackson.JacksonUtils.convertException(JacksonUtils.java:39) at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:88) at co.elastic.clients.transport.rest_client.RestClientTransport.writeNdJson(RestClientTransport.java:237) at co.elastic.clients.transport.rest_client.RestClientTransport.writeNdJson(RestClientTransport.java:234) at co.elastic.clients.transport.rest_client.RestClientTransport.prepareLowLevelRequest(RestClientTransport.java:211) at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:145) at co.elastic.clients.elasticsearch.ElasticsearchClient.bulk(ElasticsearchClient.java:310) at it.list.lookout.lka.elastic.ElasticDAO.sendBulkRequest(ElasticDAO.java:240) ... 55 more Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: **No serializer found for class** ... and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain:

Maybe there is something strange on on method BulkRequest _serializables.

Thanks in advance
Fabrizio

Activity

  1. changed the title [-]BulkOperation and IndexRequest has different behaviour with same custom JsonpSerializer serializer[/-] [+]BulkOperation and IndexRequest have different behaviour with same custom JsonpSerializer serializer[/+] on Feb 28, 2022
  2. fmarazita commented on Mar 14, 2022

    @fmarazita
    Author

    Hi
    any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions