Несовместимое ограничение равенства: Map и GetResponseJAVA

Программисты JAVA общаются здесь
Anonymous
Несовместимое ограничение равенства: Map и GetResponse

Сообщение Anonymous »

У меня есть этот код OpenSearch:

Код: Выделить всё

import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.core.GetResponse;

private OpenSearchClient client;

private Optional getDocumentResponse(BaseIndexDto request, String... indices) {
try {
final String indexName = this.getIndexName(indices);
GetRequest getRequest = new GetRequest.Builder()
.index(indexName)
.id(request.getId())
.build();
GetResponse response = client.get(getRequest, GetResponse.class);
if (response.found()) {
return Optional.of(response);
} else {
return Optional.empty();
}
} catch (Exception e) {
throw Exception("Error");
}
}
Я хочу отредактировать его следующим образом:

Код: Выделить всё

private Optional getDocumentResponse(BaseIndexDto request, String... indices) {
try {
final String indexName = this.getIndexName(indices);
GetRequest getRequest = new GetRequest.Builder()
.index(indexName)
.id(request.getId())
.build();
GetResponse response = client.get(getRequest, GetResponse.class);
if (response.found()) {
return Optional.of(response);
} else {
return Optional.empty();
}
} catch (Exception e) {
throw Exception("Error");
}
}
Но я получаю сообщение об ошибке:

Код: Выделить всё

Required type: GetResponse
Provided: GetResponse 
Incompatible equality constraint: Map and GetResponse
Мне нужно что-то вроде этого:

Код: Выделить всё

  GetResponse response = client.get(getRequest, GetResponse.class);
Как правильно это реализовать?

Подробнее здесь: https://stackoverflow.com/questions/798 ... etresponse

Вернуться в «JAVA»