keen query not working on json with arrays?

160 Views Asked by At

I am trying to do a very basic query from the explorer which looks like this:

var sensorFilter = [];
sensorFilter.push({
  property_name: "uuid",
  operator: "eq",
  property_value: "1234"
});

var avg_sensor_pm = new Keen.Query("average", {
  eventCollection: "status_update",
  targetProperty: "sensors[0].properties[0].value",
  filters: sensorFilter
});

The query returns nothing, I am wondering if the syntax to access indexed element in an array is not correct? Anybody with the same problem?

1

There are 1 best solutions below

1
On

The problem is that doing averages on values within an arrays is technically hard. I would recommend sending separate events for each status_update for each sensor and then doing an average on sensor.value.

You can definitely store arrays in Keen IO, but arrays of objects are not recommended. For more info: https://keen.io/docs/streams/data-modeling-guide/#arrays

Since I don't know anything about your data model, I should say that there might be other ways to do it too. Feel free to share it if the way I suggested wouldn't work for your use case.

Also this may be helpful: https://keen.io/docs/streams/data-modeling-guide-200/#avoid-trapping-your-data-lists