aws sdk java ver.2 cloudsearch не работает
Скажите, пожалуйста, aws sdk java ver.2 cloudsearch не работает в моем проекте. Я пробую AWS SDK Java Вер. 1.11.507 в test1.java, и он работает, то ответ json data успешен. Но AWS SDK Java Вер. 2.4.16 в test2.java имеет ошибку, как RequestID является нулем.
----------test1.java ----------
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.util.List;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.cloudsearchdomain.AmazonCloudSearchDomain;
import com.amazonaws.services.cloudsearchdomain.AmazonCloudSearchDomainClient;
import com.amazonaws.services.cloudsearchdomain.AmazonCloudSearchDomainClientBuilder;
import com.amazonaws.services.cloudsearchdomain.model.Hit;
import com.amazonaws.services.cloudsearchdomain.model.QueryParser;
import com.amazonaws.services.cloudsearchdomain.model.SearchRequest;
import com.amazonaws.services.cloudsearchdomain.model.SearchResult;
public class test1 {
public static final String ENDPOINT = "search-domain-test-nbk5oblax65pr25iuffk42jy7e.us-east-1.cloudsearch.amazonaws.com";
public static void main(String[] args) throws FileNotFoundException, URISyntaxException {
ProfileCredentialsProvider credentialsProvider = new ProfileCredentialsProvider("iemaruko");
AmazonCloudSearchDomainClientBuilder builder = AmazonCloudSearchDomainClient.builder()
.withCredentials(credentialsProvider);
EndpointConfiguration endpointConfiguration = new EndpointConfiguration(ENDPOINT, "us-east-1");
builder.withEndpointConfiguration(endpointConfiguration);
AmazonCloudSearchDomain domain = builder.build();
SearchRequest searchRequest = new SearchRequest();
searchRequest.setQueryParser(QueryParser.Simple);
searchRequest.setQuery("star");
SearchResult rslt = domain.search(searchRequest);
List<Hit> hits = rslt.getHits().getHit();
for (Hit hit : hits) {
hit.getFields().forEach((key, value) -> {
value.forEach((val) -> {
System.out.println(key + " = " + val);
});
});
}
}
}
----------test2.java ----------
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudsearchdomain.CloudSearchDomainClient;
import software.amazon.awssdk.services.cloudsearchdomain.CloudSearchDomainClientBuilder;
import software.amazon.awssdk.services.cloudsearchdomain.model.QueryParser;
import software.amazon.awssdk.services.cloudsearchdomain.model.SearchRequest;
import software.amazon.awssdk.services.cloudsearchdomain.model.SearchResponse;
public class test2 {
public static final String ENDPOINT = "http://search-domain-test-nbk5oblax65pr25iuffk42jy7e.us-east-1.cloudsearch.amazonaws.com";
public static void main(String[] args) throws FileNotFoundException, URISyntaxException {
ProfileCredentialsProvider credentialsProvider = ProfileCredentialsProvider.create("iemaruko");
URI endpointOverride = URI.create(ENDPOINT);
CloudSearchDomainClientBuilder domainClientBuilder = CloudSearchDomainClient.builder()
.credentialsProvider(credentialsProvider).region(Region.US_EAST_1).endpointOverride(endpointOverride);
CloudSearchDomainClient domainclient = domainClientBuilder.build();
System.out.println(domainclient.serviceName());
SearchRequest searchRequest = SearchRequest.builder().queryParser(QueryParser.SIMPLE).query("star")
.start((long) 1).size((long) 1).sort("sortkey1 asc,sortkey2 desc").returnValues("_score,title,ranking").build();
SearchResponse searchResponse = domainclient.search(searchRequest);
System.out.println(searchResponse.toString());
}
}