I have the following log insights sql
fields jointStates.jointVariables.posSi.0 as pos0, jointStatesRef.jointVariables.posSi.0 as refPos0
| stats
avg((pos0-refPos0)*(pos0-refPos0)) as j0_pos_err,
by bin(1s)
That i am trying to convert into the open search sql format . AI tools have given this to me
SELECT
DATE_HISTOGRAM(@timestamp, '1s') as time_bucket,
AVG(POW(
jointStates.jointVariables.posSi['0'] - jointStatesRef.jointVariables.posSi['0'],
2)
) as j0_pos_err
FROM simulation-telemetry
GROUP BY DATE_HISTOGRAM(@timestamp, '1s')
ORDER BY time_bucket;
But the syntax is wrong. Was hoping to get some assistance
I have the following log insights sql
fields jointStates.jointVariables.posSi.0 as pos0, jointStatesRef.jointVariables.posSi.0 as refPos0
| stats
avg((pos0-refPos0)*(pos0-refPos0)) as j0_pos_err,
by bin(1s)
That i am trying to convert into the open search sql format . AI tools have given this to me
SELECT
DATE_HISTOGRAM(@timestamp, '1s') as time_bucket,
AVG(POW(
jointStates.jointVariables.posSi['0'] - jointStatesRef.jointVariables.posSi['0'],
2)
) as j0_pos_err
FROM simulation-telemetry
GROUP BY DATE_HISTOGRAM(@timestamp, '1s')
ORDER BY time_bucket;
But the syntax is wrong. Was hoping to get some assistance
Share Improve this question edited Apr 4 at 0:43 fa44 5511 gold badge4 silver badges11 bronze badges asked Mar 3 at 19:43 raajraaj 3,3317 gold badges44 silver badges69 bronze badges1 Answer
Reset to default 0You can try following:
SELECT
DATE_TRUNC('SECOND', `@timestamp`) time_bucket,
INT(AVG(POW(
get_json_object(`@message`, '$.jointStates.jointVariables.posSi.0') - get_json_object(`@message`, '$.jointStatesRef.jointVariables.posSi.0'),
2))
) as j0_pos_err
FROM `simulation-telemetry`
GROUP BY DATE_TRUNC('SECOND', `@timestamp`)
ORDER BY time_bucket desc
- Not sure how
DATE_HISTOGRAM
is working butDATE_TRUNC
should be good to replacebin
function. - I don't know if it's possible to access
jointStates
/jointStatesRef
fields directly from the root withOpenSearch SQL
, but from@message
, that's something possible. - I added a cast to
INT
, because the result is afloat
, but you can adjust that part with your needs.
Some other OpenSearch SQL
details here if you're insterested.