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
已提問 1 年前檢視次數 1968 次
3 個答案
1
已接受的答案

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
專家
已回答 1 年前
  • 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

已回答 7 個月前
  • 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

已回答 7 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南