OpenSearch
OpenSearch copied to clipboard
[BUG] Direct self-reference leading to cycle
Describe the bug
When a failure is met with one or more operations included in the bulk request, the ObjectMapper.writeValueAsString that we use to convert the bulk response throws the following exception:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle
and fails to convert the Bulkresponse.
With ElasticSearch, however, it works just fine and never throws this exception.
We use RestHighLevelClient for both.
To Reproduce Steps to reproduce the behavior:
- Run the following piece of code
ObjectMapper objectMapper = new ObjectMapper();
try {
String jsonArray = objectMapper.writeValueAsString( bulkResponse.getItems() );
}
catch ( JsonProcessingException jsonProcessingException ) {
log.error( jsonProcessingException.getMessage() );
throw new RuntimeException( jsonProcessingException );
}
- See the following error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle ( through reference chain: org.elasticsearch.action.bulk.BulkItemResponse[2]-> org.elasticsearch.action.bulk.BulkItemResponse["failure"]-> org.elasticsearch.action.bulk.BulkItemResponse$Failure["cause"]-> org.elasticsearch.ElasticsearchException["rootCause"] )
Expected behavior ObjectMapper.writeValueAsString should return JSON formatted text output of Bulkresponse without exception.
Plugins
Please see the list of all plugins currently enabled.

Host/Environment (please complete the following information):
- MacOS 12.0.1
- opensearch:latest
Additional context The same code doesn't throw any exception and works well with ElasticSearch.
Hi @ersinoracle, Could you share the object before the serialization? the output of bulkResponse.getItems(), so we can reproduce it. In addition, could share more details about your use-case? what is the problem you are trying to solve?
Please see the answers below.
Use-case:
- Call bulk API using the payload which is assigned into the
requestBodyactual parameter - Convert the response to JSON so to return it to the caller
Problem:
- ObjectMapper throws exception
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle.
Files attached (had to add .txt at the end of each file extension to be able to attach):
Any updates yet?
I labeled this for 1.3.0 so we don't miss it.
@ersinoracle Try turning this into a unit test if you have a moment?
@dblock I, unfortunately, won't have time to write a unit test for this. But, I'll be waiting for you to address and resolve the issue hopefully in 1.3.0.
Hey @ersinoracle, Sorry for being late. are you currently try to use elasticsearch client to query OpenSearch cluster.?Because the error has elasticsearch, I want to confirm this before diving into the issue.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle ( through reference chain: org.elasticsearch.action.bulk.BulkItemResponse[2]-> org.elasticsearch.action.bulk.BulkItemResponse["failure"]-> org.elasticsearch.action.bulk.BulkItemResponse$Failure["cause"]-> org.elasticsearch.ElasticsearchException["rootCause"] )
Hi @anasalkouz, yes we still have been using it to query the OpenSearch cluster.
Starting with version 7.14, multiple of the clients maintained by Elastic start to fail query OpenSearch Cluster. I would recommend update it to the equivalent OpenSearch client. See this blog for more details
@anasalkouz this issue is tagged 2.1.0. We are code freeze for 2.1. I'll move this issue to 2.2.0, let me know if you think otherwise.
Closing this issue. @ie-senol let me know if there is anything still pending on this to reopen.