title: How do I query by only part of a composite key in DynamoDB?
body: <p>Let's say, I have <code>User</code>s writing reviews of <code>Product</code>s.</p>
  <p>User and Product are separate entities with their own ids.</p>
  <p><code>Review</code> is an entity with a composite id composed of <code>userId</code> and <code>productId</code>.</p>
  <p>I have created a table <code>review</code> in DynamoDB with both <code>userId</code> and <code>productId</code> as HASH keys.</p>
  <pre><code>aws dynamodb create-table --table-name review \
    --attribute-definitions \
        AttributeName=user_id,AttributeType=S \
        AttributeName=product_id,AttributeType=S \
    --key-schema \
        AttributeName=user_id,KeyType=HASH \
        AttributeName=product_id,KeyType=RANGE \
    --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 
  </code></pre>
  <p>Thus making <code>userId</code>+<code>productId</code> the composite key.</p>
  <p>The review data object is held against that key.</p>
  <p>Querying for a review by user and product is fine.</p>
  <p>But how do I query for all reviews by a user or all reviews for a product?</p>
  <p>With a single parameter, e.g. if I do a query by single key conditional expression with just <code>&quot;#user_id = :userId&quot;</code> or just  <code>&quot;#product_id = :productId&quot;</code></p>
  <p>I get an error of the form</p>
  <pre><code>Query condition missed key schema element: user_id
  </code></pre>
  <p>or</p>
  <pre><code>Query condition missed key schema element: product_id
  </code></pre>