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
질문됨 일 년 전1910회 조회
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
전문가
답변함 일 년 전
  • 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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠