opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
124 stars 183 forks source link

[BUG] Request failed: [parse_exception] missing suggestion object #459

Closed ungeordnet closed 1 year ago

ungeordnet commented 1 year ago

What is the bug?

When I send a Suggestionrequest the response cannot be parsed because of the following exception:

 org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [parse_exception] missing suggestion object
    at org.opensearch.client.transport.aws.AwsSdk2Transport.parseResponse(AwsSdk2Transport.java:486)
    at org.opensearch.client.transport.aws.AwsSdk2Transport.executeSync(AwsSdk2Transport.java:393)
    at org.opensearch.client.transport.aws.AwsSdk2Transport.performRequest(AwsSdk2Transport.java:191)
    at org.opensearch.client.opensearch.OpenSearchClient.search(OpenSearchClient.java:1219)
    at com.heiland.searchservice.repository.AbstractOpenSearchRepository.autocomplete(AbstractOpenSearchRepository.java:48)
    ... 176 common frames omitted

My implementation is as follows:

try {

  final CompletionSuggester completion = CompletionSuggester.of(c -> c.field("suggestions"));
  final FieldSuggester fieldSuggester = FieldSuggester.of(f -> ((FieldSuggester.Builder) f.completion(completion)).prefix("Haut"));
  final SearchRequest request = SearchRequest.of(s -> s.index(searchIndex()).suggest(Suggester.of(s -> s.suggesters("autocomplete", fieldSuggester))));

  return client.search(request, Object.class);

  } catch (final Exception e) {
    throw new RuntimeException(e);
  }

This implementation shall represent the following query:

GET index/_search { "suggest": { "autocomplete": { "prefix": "Haut", "completion": { "field": "suggestions" } } } }

What is the expected behavior?

I expect that the reponse can be parsed and the SearchRepsonse has the field suggest is filled propertly.

What is your host/environment?

ungeordnet commented 1 year ago

Hej

unfortunattly the Bug is not fixed with #477 . I just updated my project and run the code and get the same error as before:

2023-06-09T06:18:32,408Z [http-nio-8082-exec-1] t35tTr4c31D ERROR GlobalExceptionHandler:39 - An internal error occurred org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [parse_exception] missing suggestion object at org.opensearch.client.transport.aws.AwsSdk2Transport.parseResponse(AwsSdk2Transport.java:492) at org.opensearch.client.transport.aws.AwsSdk2Transport.executeSync(AwsSdk2Transport.java:393) at org.opensearch.client.transport.aws.AwsSdk2Transport.performRequest(AwsSdk2Transport.java:191) at org.opensearch.client.opensearch.OpenSearchClient.search(OpenSearchClient.java:1302) at com.heiland.searchservice.repository.AbstractOpenSearchRepository.autocomplete(AbstractOpenSearchRepository.java:107) ... 176 common frames omitted

VachaShah commented 1 year ago

@harshavamsi Can you take a look at this?