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
demandé il y a un an1910 vues
3 réponses
1
Réponse acceptée

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
EXPERT
répondu il y a un an
  • 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

répondu il y a 7 mois
  • 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

répondu il y a 7 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions