最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Log insights ql to Opensearch - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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 but DATE_TRUNC should be good to replace bin function.
  • I don't know if it's possible to access jointStates/jointStatesRef fields directly from the root with OpenSearch SQL, but from @message, that's something possible.
  • I added a cast to INT, because the result is a float, but you can adjust that part with your needs.

Some other OpenSearch SQL details here if you're insterested.

发布评论

评论列表(0)

  1. 暂无评论