1

I have on a table a global secondary index with hash and range keys. I want to fetch in a single query entries with a specific hash key and a certain list of possible range values.

I tried this, but getting an exception:

DynamoDBQueryExpression<MyClass> queryExpression = new DynamoDBQueryExpression<>();
        queryExpression.setIndexName("globalSecondaryIndexName");
        queryExpression.setConsistentRead(false);
        queryExpression.setHashKeyValues(new MyClass(indexHashKeyValue));
        Map<String, Condition> rangeKeyConditions = new HashMap<>();
        rangeKeyConditions.put("rangeKeyName", new Condition().withComparisonOperator(ComparisonOperator.IN).
                withAttributeValueList(ids.stream().map(AttributeValue::new).collect(Collectors.toList())));
        queryExpression.setRangeKeyConditions(rangeKeyConditions);
        PaginatedQueryList<MyClass> paginatedQueryList = db.query(MyClass.class, queryExpression);

Getting this exception:

Exception in thread "main" com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: Attempted conditional constraint is not an indexable operation (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 4c7d2a81-ad80-4f06-b565-939716adfc20)

Also tried ComparisonOperator.EQ, but getting: Exception in thread "main" com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: One or more parameter values were invalid: Invalid number of argument(s) for the EQ ComparisonOperator

dor.elmaliach
  • 515
  • 5
  • 14

0 Answers0