title: Converting a painless script into a visualisation on Kibana (Logs from AWS Connect)
body: <p>I have logs being shipped from AWS Connect to Kibana through AWS OpenSearch. I have written the following script to return the latest status of an Agent like so:</p>
  <pre><code>GET agent-logs-*/_search
  {
      &quot;script_fields&quot;: {
          &quot;data&quot;: {
              &quot;script&quot;: {
                  &quot;lang&quot;: &quot;painless&quot;,
                  &quot;source&quot;: &quot;params._source.CurrentAgentSnapshot.Configuration.Username + ', ' + params._source.CurrentAgentSnapshot.AgentStatus.Name + ', ' + params._source.EventTimestamp&quot;
              }
          }
      },
      &quot;collapse&quot;: {
      &quot;field&quot;: &quot;CurrentAgentSnapshot.Configuration.Username.keyword&quot;
    },
    &quot;sort&quot;: [
      {
        &quot;EventTimestamp&quot;: {
          &quot;order&quot;: &quot;desc&quot;
        }
      }
    ]
  }
  </code></pre>
  <p>This returns a value of:</p>
  <pre><code>{
    &quot;took&quot; : 29,
    &quot;timed_out&quot; : false,
    &quot;_shards&quot; : {
      &quot;total&quot; : 65,
      &quot;successful&quot; : 65,
      &quot;skipped&quot; : 0,
      &quot;failed&quot; : 0
    },
    &quot;hits&quot; : {
      &quot;total&quot; : {
        &quot;value&quot; : 10000,
        &quot;relation&quot; : &quot;gte&quot;
      },
      &quot;max_score&quot; : null,
      &quot;hits&quot; : [
        {
          &quot;_index&quot; : &quot;agent-logs-2022-06-28&quot;,
          &quot;_type&quot; : &quot;_doc&quot;,
          &quot;_id&quot; : &quot;&quot;,
          &quot;_score&quot; : null,
          &quot;fields&quot; : {
            &quot;data&quot; : [
              &quot;al.pacino@email.com, Available, 2022-06-28T10:52:01.238Z&quot;
            ],
            &quot;CurrentAgentSnapshot.Configuration.Username.keyword&quot; : [
              &quot;al.pacino@email.com&quot;
            ]
          },
          &quot;sort&quot; : [
            1656413521238
          ]
        },
        {
          &quot;_index&quot; : &quot;agent-logs-2022-06-28&quot;,
          &quot;_type&quot; : &quot;_doc&quot;,
          &quot;_id&quot; : &quot;&quot;,
          &quot;_score&quot; : null,
          &quot;fields&quot; : {
            &quot;data&quot; : [
              &quot;robert.deniro@email.com, Available, 2022-06-28T10:50:45.622Z&quot;
            ],
            &quot;CurrentAgentSnapshot.Configuration.Username.keyword&quot; : [
              &quot;robert.deniro@email.com&quot;
            ]
          },
          &quot;sort&quot; : [
            1656413445622
          ]
        },
        {
          &quot;_index&quot; : &quot;agent-logs-2022-06-26&quot;,
          &quot;_type&quot; : &quot;_doc&quot;,
          &quot;_id&quot; : &quot;&quot;,
          &quot;_score&quot; : null,
          &quot;fields&quot; : {
            &quot;data&quot; : [
              &quot;marlon.brando@email.com, Offline, 2022-06-26T14:51:55.203Z&quot;
            ],
            &quot;CurrentAgentSnapshot.Configuration.Username.keyword&quot; : [
              &quot;marlon.brando@email.com&quot;
            ]
          },
          &quot;sort&quot; : [
            1656255115203
          ]
        }
      ]
    }
  }
  </code></pre>
  <p>I wanted to take the data lines from the JSON - &quot;al.pacino@email.com, Available, 2022-06-28T10:52:01.238Z&quot; and <strong>represent this in a visualisation</strong> such as a Data Table to get a list of agents with their corresponding status.</p>
  <p>By using the current agent-logs, there is a delay whereby the status change and heart beats overlap, causing an inaccurate count of the status, thus need to use this script.</p>