Creating a visualization: aggregate data over time

I am likely using the wrong terms... or I would have found this in my searching...

I am getting documents every day that list activity for objects. Eg:
Day 1:

{
    objectOne: {
        countOfFirstAction: 3,
        countOfSecondAction: 1
    },
    objectTwo: {
        countOfFirstAction: 5,
        countOfSecondAction: 0
    }
}

Day 2:

{
    objectOne: {
        countOfFirstAction: 4,
        countOfSecondAction: 6
    },
    objectTwo: {
        countOfFirstAction: 3,
        countOfSecondAction: 2
    }
}

I want to build a graph that will show the change in number of actions over time. Something like a line graph with dates on the bottom, and the totals for 'FirstAction' and 'SecondAction' plotted for each day.

So:
day 1 would show 'FirstAction' == '8', and 'SecondAction' == '1'
day 2 would show 'FirstAction' == '7', and 'SecondAction' == '8'

This seems like it would be easy, but using the lens results in unexpected graphs.

Hello, Could you paste a screenshot of what you've created with Lens and what you're trying to achieve?

1 Like

I'm not sure what you exactly want and screenshot will help us to answer correctly,

I suppose, however, you need a runtime field.

Using Dev Tools:

PUT your_index/_mapping
{
  "runtime":{
    "FirstAction":{
      "type":"long",
      "script": {"source": "emit(doc['objectOne.countOfFirstAction'].value + doc['objectTwo.countOfFirstAction'].value )"}
    },
    "SecondAction":{
      "type":"long",
      "script": {"source": "emit(doc['objectOne.countOfSecondAction'].value + doc['objectTwo.countOfSecondAction'].value )"}
    }
  }
}

Then, you can use FirstAction and SecondAction in Lens.

Another way could be using copy_to parameter BEFORE indexing documents and use that field to aggregate & visualize.

2 Likes

I was trying to obfuscate the real data in my example. When I was asked for a screen shot, I added the above data... more or less... and tried to reproduce the problem so that I could take a screenshot.

Turns out that what I mostly needed was:
#1: for the vertical axis: Each 'action' should use the function "sum"
#2: for the horizontal axis: Choose 'date histogram', and for the timestamp, choose 'customize time interval' to '1 days'.

Simple stuff really... but I was tripping over some overly complicated filtering, and missing the time interval option.

That said, your response was very enlightening. Ill put that in my back pocket for when I need it. Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.