title: DynamoDB - fetching items by multiple keys
body: <p>started using <code>DynamoDB</code> recently and I am having problems fetching data by multiple keys.</p>
  
  <p>I am trying to get multiple items from a table.</p>
  
  <p>My table schema is defined as follows:</p>
  
  <pre><code>{
    "AttributeDefinitions": [
      {
        "AttributeName": "id",
        "AttributeType": "S"
      },
      {
        "AttributeName": "date",
        "AttributeType": "S"
      }
    ],
    "KeySchema": [
      {
        "AttributeName": "id",
        "KeyType": "HASH"
      },
      {
        "AttributeName": "date",
        "KeyType": "RANGE"
      }
    ],
    ...
  }
  </code></pre>
  
  <p>I have a filter list of ids and a date range for each id:</p>
  
  <pre><code>[
      { "id": "abc", "start_date": "24/03/2020", "end_date": "26/03/2020" },
      { "id": "def", "start_date": "10/04/2020", "end_date": "20/04/2020" },
      { "id": "ghi", "start_date": "11/04/2020", "end_date": "11/04/2020" }
  ]
  </code></pre>
  
  <p>I need to fetch all items that match the filter list.</p>
  
  <p>The problem is that I cannot use <code>Query</code> as <code>KeyConditionExpression</code> only accepts a single partition key (and I need to match it to the entire filter list)</p>
  
  <blockquote>
    <p>The condition must perform an equality test on a single partition key value.</p>
  </blockquote>
  
  <p>I cannot use <code>BatchGetItem</code> as it requires the exact key (and I need a date range for my sort key <code>Key('date').between(start_date, end_date)</code>)</p>
  
  <blockquote>
    <p>Keys - An array of primary key attribute values that define specific items in the table. For each primary key, you must provide all of the key attributes. For example, with a simple primary key, you only need to provide the partition key value. For a composite key, you must provide both the partition key value and the sort key value.</p>
  </blockquote>
  
  <p>I am kind of lost...
  Is there a way to fetch by multiple keys with a range query (by a single request - not multiple requests from a loop)?</p>
  
  <p>Would you suggest any table changes?</p>