title: Filter expression based on a nested attribute in an array - DynamoDB
body: <p>I have a DynamoDB table where I store this data;</p>
  
  <p><a href="https://i.stack.imgur.com/1iO17.png" rel="nofollow noreferrer">JSON data</a></p>
  
  <p>where "device" is the partition key and "datetime" the sort key.
  I'm able to query data based on PartitionKey and range of dates (sort key). But now, I would need to filter based on "endpoint" which is inside "data" which is an array. For example, I would like to retrieve the data only if endpoint 1 exist in data array, or for example if endpoint IN (1,3) exist.
  I 'm using following code;</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var dev = event.params.querystring.device;    
  var from = event.params.querystring.from;
  var to  = event.params.querystring.to;
  var ascord = event.params.querystring.ascord;
  var limit = event.params.querystring.limit;
  
    
  var qryParams = {
    TableName : "mytable",
    KeyConditionExpression: "#id = :dddd and #tm between :time1 and :time2",
    FilterExpression: "data.endpoint = :ep",
    ExpressionAttributeNames:{
        "#id": "device",
        "#tm": "datetime"
    },
    ExpressionAttributeValues: {
        ":dddd": dev,
        ":time1": from, 
        ":time2": to, 
        ":ep": 1
    }
  };
  
  docClient.query(qryParams, function(err, data){
      if (err){
          callback(err, null);
      }else {
          callback(null, data);
      }
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it doesn't retrieve any record. I also tried to use placeholders (#data.#endpoint) but didn't work.
  What would be the right way to do it?
  Also, should I create an index in the table for the endpoints?</p>
  
  <p>Thanks for your help.
  Regards;
  Gus</p>