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
asked 10 months ago1351 views
3 Answers
1
Accepted Answer

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
answered 10 months ago
  • 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

answered 4 months ago
  • 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

answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions