2

I am using Elasticsearch 2.3 and for each web page a user visits in my website I produce a record with user session id and current timestamp.
So I have few records with same session id but different timestamp.
I'm trying to create a date_histogram with unique session ids from users records.

Creating the histogram without the uniqueness is easy:

{
    "aggs" : {
        "users_sessions" : {
            "date_histogram" : {
                "field" : "date",
                "interval" : "1h"
            }
        }
    }
}

But is it possible to have such date histogram with unique values (for example, with the first occurrence of each unique session id)?

ItayD
  • 533
  • 6
  • 23

1 Answers1

5

Try this

{
  "size": 0,
  "aggs": {
    "users_sessions": {
      "date_histogram": {
        "field": "date",
        "interval": "1h",
        "min_doc_count": 0
      },
        "aggs": {
        "3": {
          "cardinality": {
            "field": "session_id"
          }
        }
      }
    }
  }
}

cardinality parameter get unique session ids per hour.

Kenan Duman
  • 154
  • 1
  • 5