elastic / elastic/elasticsearch-java

BulkOperation and IndexRequest have different behaviour with same custom JsonpSerializer serializer

Open
#172 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
524
Forks
300
Avg merge
1d 11h
Merged PRs (30d)
16

Description

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 indexRequest(String index, B bean) {
CustomSerializer serialize = new CustomSerializer<>(...); //-> where CustomSerializer implements JsonpSerializer
return new IndexRequest.Builder()
.index(index)
.id(createElasticId(bean))
.tDocumentSerializer(serialize)
.document(bean)
.build();
}
```

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

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

public IndexResponse sendIndexRequest(IndexRequest 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.