Несовместимое ограничение равенства: 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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