elastic/elasticsearch-java

Failed to decode response on synonyms.putSynonym

cato-dll opened this issue · 1 comments

Java API client version

8.12

Java version

21

Elasticsearch Version

8.12

Problem description

The issue might be similar to the problems discussed here: https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.12/missing-required-property.html, but in this case, receive the error.

It should be NOTED that the updating of the synonym set is SUCCESSFUL. Despite throwing the exception. So my work around at this time, is to just catch it and carry on.

It should also be noted that this code is an attempt to work around the fact that I can update a single entry, as documented here: #739

co.elastic.clients.transport.TransportException: node: [https://xxxxx.es.us-east-1.aws.found.io:443/](https://xxxxxxx.es.us-east-1.aws.found.io/), status: 200, [es/synonyms.put_synonym] Failed to decode response
at co.elastic.clients.transport.ElasticsearchTransportBase.decodeTransportResponse(ElasticsearchTransportBase.java:404)
at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:363)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:147)
at co.elastic.clients.elasticsearch.synonyms.ElasticsearchSynonymsClient.putSynonym(ElasticsearchSynonymsClient.java:257)
at co.elastic.clients.elasticsearch.synonyms.ElasticsearchSynonymsClient.putSynonym(ElasticsearchSynonymsClient.java:273)
at test.grissom.ai.AiTest.synonyms(AiTest.java:132)
at test.grissom.ai.AiTest.main(AiTest.java:84)
Caused by: co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.synonyms.PutSynonymResponse: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'ReloadDetails.index' (JSON path: reload_analyzers_details) (line no=1, column no=119, offset=-1)
at co.elastic.clients.json.JsonpMappingException.from0(JsonpMappingException.java:134)
at co.elastic.clients.json.JsonpMappingException.from(JsonpMappingException.java:121)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:218)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:148)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
at co.elastic.clients.transport.ElasticsearchTransportBase.decodeTransportResponse(ElasticsearchTransportBase.java:399)
… 6 more
Caused by: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'ReloadDetails.index'
at co.elastic.clients.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:76)
at co.elastic.clients.elasticsearch.indices.reload_search_analyzers.ReloadDetails.<init>(ReloadDetails.java:63)
at co.elastic.clients.elasticsearch.indices.reload_search_analyzers.ReloadDetails.<init>(ReloadDetails.java:52)
at co.elastic.clients.elasticsearch.indices.reload_search_analyzers.ReloadDetails$Builder.build(ReloadDetails.java:212)
at co.elastic.clients.elasticsearch.indices.reload_search_analyzers.ReloadDetails$Builder.build(ReloadDetails.java:143)
at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:80)
at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:192)
… 11 more

Here is some test code:

public static void updateSynonyms()
{
	String synonymSet = "cs-search-synonym-set";
	String ruleId = "c1719329-a3f4-4e27-a74e-64db17d85d06";
	String newSynonyms = "one,two,three";
	
	try
	{
		Header[] config = new Header[] 
		{
				new BasicHeader("Authorization", "ApiKey " + ApplicationConstants.ELASTIC_API_KEY) 
		};

		RestClientBuilder restClient = RestClient.builder(new HttpHost(ApplicationConstants.ELASTIC_HOST, 443, "https"));
		restClient.setDefaultHeaders(config);

		try (ElasticsearchTransport transport = new RestClientTransport(restClient.build(), new JacksonJsonpMapper()))
		{
			ElasticsearchClient client = new ElasticsearchClient(transport);

			ElasticsearchSynonymsClient synonyms = client.synonyms();

			// fetch all the synonyms
			GetSynonymResponse currentSynSet = synonyms.getSynonym(r->r.id(synonymSet).size(10000));
			
			List<SynonymRule> rules = new ArrayList<SynonymRule>();
			
			// loop through the set and update the record that we need too
			List<SynonymRuleRead> listOfValues = currentSynSet.synonymsSet();
			for (int i=0; i < listOfValues.size(); i++)
			{
				SynonymRuleRead v = listOfValues.get(i);

				// this will replace/update the old entry with the new one, since I can't directly
				//	update the synonym by id -- https://github.com/elastic/elasticsearch-java/issues/739
				if (v.id().equalsIgnoreCase(ruleId))
				{
					rules.add(SynonymRule.of(r->r.id(ruleId).synonyms(newSynonyms)));
				}
				else
				{
					rules.add(SynonymRule.of(r->r.id(v.id()).synonyms(v.synonyms())));
				}
			}
			
			try
			{
				// update the entire synonym set, instead of the one we really want to
				synonyms.putSynonym(s->s.synonymsSet(rules).id(synonymSet));
			}
			catch(Exception e)
			{
				// temporary work around until Elastic fixes their API
				LOGGER.info("STILL ACCEPTING AS VALID - "  + e.getLocalizedMessage());
			}
		}
	} 
	catch (ElasticsearchException e)
	{
		e.printStackTrace();
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
}

The following is a subset of the the wire-level logs:

2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "PUT /_synonyms/cs-search-synonym-set HTTP/1.1[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "X-Elastic-Client-Meta: es=8.12.0,jv=21,t=8.12.0,hl=2,hc=4.1.5,kt=1.9[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "User-Agent: elastic-java/8.12.0 (Java/21.0.1)[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Accept: application/vnd.elasticsearch+json; compatible-with=8[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Authorization: ApiKey REMOVED[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Transfer-Encoding: chunked[\r][\n]"
2024-01-30T00:09:12.537Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Content-Type: application/vnd.elasticsearch+json; compatible-with=8[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Host: xxxxxx.es.us-east-1.aws.found.io:443[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "Connection: Keep-Alive[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "368[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "{"synonyms_set":[{"id":"177fe917-52d7-4d7e-b0b2-b118c850cd83","synonyms":"universal shares,ushares,more"},{"id":"2761f764-1d28-4d25-aad5-c44f878b274c","synonyms":"d364e140-e38d-4821-b8cf-e216da63c0b4 -> 5e181a9d-5bf1-4970-800d-6ed80ded6e50"},{"id":"33a28b08-b558-4707-9d97-5fe96509ae87","synonyms":"enterprise administrator, ea"},{"id":"34b32bb3-fafb-4310-8466-ffaf6bbad5f8","synonyms":"20019de7-c995-436d-a434-a628a319ce6b -> 4790d338-3323-42a0-8fa4-0e94d96a374e"},{"id":"54299a6b-f0ea-43d7-afc4-7e34e8fe7dab","synonyms":"6e4b3ff3-629d-4056-b969-27abdd834cee -> a902c70c-35e3-4e70-8b5c-e6f7a244820c"},{"id":"664340ae-b1e6-4d95-a7d6-06edf265b740","synonyms":"testing one, two, three."},{"id":"927b5f73-7d90-4128-932b-fd97eb21d105","synonyms":"hardware compatibility list, hcl"},{"id":"2c55cfa4-fea8-4a7c-bacf-2ff9cbdf9c67","synonyms":"testing one, two, three."}]}[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "0[\r][\n]"
2024-01-30T00:09:12.538Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 >> "[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "HTTP/1.1 200 OK[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "Content-Length: 119[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "Content-Type: application/vnd.elasticsearch+json;compatible-with=8[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "X-Cloud-Request-Id: iimfDis8SYWln5lnDAkPkw[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "X-Elastic-Product: Elasticsearch[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "X-Found-Handling-Cluster: 97091b90cd4b406c84b1ab0d77d2e713[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "X-Found-Handling-Instance: instance-0000000012[\r][\n]"
2024-01-30T00:09:13.640Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "Date: Tue, 30 Jan 2024 00:09:13 GMT[\r][\n]"
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "[\r][\n]"
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.wire                     : http-outgoing-1 << "{"result":"updated","reload_analyzers_details":{"_shards":{"total":80,"successful":80,"failed":0},"reload_details":[]}}"
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << HTTP/1.1 200 OK
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << Content-Length: 119
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << Content-Type: application/vnd.elasticsearch+json;compatible-with=8
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << X-Cloud-Request-Id: iimfDis8SYWln5lnDAkPkw
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << X-Elastic-Product: Elasticsearch
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << X-Found-Handling-Cluster: 97091b90cd4b406c84b1ab0d77d2e713
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << X-Found-Handling-Instance: instance-0000000012
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] org.apache.http.headers                  : http-outgoing-1 << Date: Tue, 30 Jan 2024 00:09:13 GMT
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] o.a.h.i.nio.client.InternalIODispatch    : http-outgoing-1 [ACTIVE(119)] Response received
2024-01-30T00:09:13.641Z DEBUG 2364 --- [O dispatcher 17] o.a.http.impl.nio.client.MainClientExec  : [exchange: 3] Response received HTTP/1.1 200 OK

Closing this as already fixed, see the comment on #739