Quering GSI of DynamoDB using QueryEnhancedRequest

0

Can some one help in letting me know how I can create query to GSI of DynamoDB using QueryEnhancedRequest in Java??

In most of the AWS documentation I see that they provided examples with QueryRequest but not with QueryEnhancedRequest and DynamoDbTable<T> is only accepting the query of type QueryEnhancedRequest in Jva

Sathwik
posta un anno fa2005 visualizzazioni
3 Risposte
1
Risposta accettata

Here's an example:

        DynamoDbTable<Movie> moviesTable = enhancedClient.table("Movies", TableSchema.fromBean(Movie.class));

        QueryConditional condition = QueryConditional.sortBetween(Key.builder()
                .partitionValue(1958)
                .sortValue("1920")
                .build(), Key.builder()
                .partitionValue(1958)
                .sortValue("1950")
                .build());

        QueryEnhancedRequest request = QueryEnhancedRequest.builder()
                .queryConditional(condition)
                .scanIndexForward(false)
                .build();

        SdkIterable<Page<Movie>> movieWithName = moviesTable.index("my-index").query(request);

        movieWithName.forEach(page-> {
            List<Movie> allMovies = page.items();
            for( Movie myMovie: allMovies){
                System.out.println(myMovie.getTitle());
            }
        });
profile pictureAWS
ESPERTO
con risposta un anno fa
  • Hi @Leeroy Hannigan, Thank you for your quick response it is working as I expected It is very helpful

0

@Leeroy Hannigan , Thank you for your post and how to use limit here? and we trying use limit but getting all items.. please help me to fix this issue? and Most of person telling limit is not supported in QueryEnhancedRequest

QueryEnhancedRequest.Builder queryRequest = QueryEnhancedRequest.builder() .queryConditional(queryConditional) .filterExpression(expressions) .scanIndexForward(false) .limit(50);

		   SdkIterable<Page<Records>> recordsListIterable =dynamoDbRecordTable.index("ByScheduleDate").query(queryRequest.build());

for Ref: https://stackoverflow.com/questions/62417472/limit-method-in-queryenhancedrequest-for-dynamodb-java-v2-sdk-doesnt-limit-as-e

con risposta 7 mesi fa
  • Limit is supported, please ask a new question and I will answer it.

0

Hi @Leeroy Hannigan, We are tried with limit but query returns all items.

Key	startKey=Key.builder().partitionValue(Messages.YES.getCode()).sortValue(startDate).build();
			Key	endKey=Key.builder().partitionValue(Messages.YES.getCode()).sortValue(endDate).build();
			QueryConditional queryConditional = QueryConditional.sortBetween(startKey, endKey);

		Expression expressions= Expression.builder().expression(expressionStr.toString()).expressionValues(filterParamMap).build();

QueryEnhancedRequest.Builder queryRequest = QueryEnhancedRequest.builder() .queryConditional(queryConditional) .filterExpression(expressions) .scanIndexForward(false).limit(50);

	 SdkIterable<Page<Records>> recordsListIterable =dynamoDbRecordTable.index("ByScheduleDate").query(queryRequest.build());
		   
		   recordsListIterable.stream().forEach(rec -> {
			   totalRecordsList.addAll(rec.items());
		   });

So i posted the questions here. Could you please hlep us?

for Ref : https://stackoverflow.com/questions/62417472/limit-method-in-queryenhancedrequest-for-dynamodb-java-v2-sdk-doesnt-limit-as-e

con risposta 7 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande