Giter Club home page Giter Club logo

Comments (2)

ylasri avatar ylasri commented on July 28, 2024

Here is example of setup Cohort plugin. Tested on Kibana 7.8.0, 7.8.1 and 7.9.0

  1. Set mapping what defines '@timestamp' (when doc was created, in our example order_date) and 'first_order_date' (when user/item was created for active for the first time) fields as date type,
    also you can define 'dayUntilReturn' if you'll not create it as scripted field (step 3) :
PUT food_relay
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "common_id": {
        "type": "keyword"
      },
      "dayUntilReturn": {
        "type": "integer"
      },
      "first_order_date": {
        "type": "date"
      },
      "order_date": {
        "type": "date"
      },
      "order_id": {
        "type": "keyword"
      },
      "pickup_date": {
        "type": "date"
      },
      "pup_id": {
        "type": "keyword"
      },
      "total_charges": {
        "type": "float"
      },
      "user_id": {
        "type": "keyword"
      }
    }
  }
}

2- Put some cohort similar data : use _bulk file food_relay_es_bulk.csv.json under dataset folder

POST _bulk
{"index": {"_index": "food_relay", "_id": 262}}
{"order_id": "262", "order_date": "2009-01-11", "user_id": "47", "total_charges": "50.67", "common_id": "TRQKD", "pup_id": "2", "pickup_date": "2009-01-12", "first_order_date": "2009-01-11", "dayUntilReturn": "0"}
{"index": {"_index": "food_relay", "_id": 278}}
{"order_id": "278", "order_date": "2009-01-20", "user_id": "47", "total_charges": "26.6", "common_id": "4HH2S", "pup_id": "3", "pickup_date": "2009-01-20", "first_order_date": "2009-01-11", "dayUntilReturn": "9"}
{"index": {"_index": "food_relay", "_id": 294}}
{"order_id": "294", "order_date": "2009-02-03", "user_id": "47", "total_charges": "38.71", "common_id": "3TRDC", "pup_id": "2", "pickup_date": "2009-02-04", "first_order_date": "2009-01-11", "dayUntilReturn": "23"}
{"index": {"_index": "food_relay", "_id": 301}}
{"order_id": "301", "order_date": "2009-02-06", "user_id": "47", "total_charges": "53.38", "common_id": "NGAZJ", "pup_id": "2", "pickup_date": "2009-02-09", "first_order_date": "2009-01-11", "dayUntilReturn": "26"}
{"index": {"_index": "food_relay", "_id": 302}}

3- Alternative to 'dayUntilReturn' is to create scripted field with same name and next value:
(doc['order_date'].value.toInstant().toEpochMilli() - doc['first_order_date'].value.toInstant().toEpochMilli()) / (1000 * 60 * 60* 24)
To calculate days diff on elastic side.

GET food_relay/_search
{
  "_source": ["first_order_date", "order_date", "dayUntilReturn"],  
  "script_fields": {
    "daysBetween": {
      "script": {
        "source": "(doc['order_date'].value.toInstant().toEpochMilli() - doc['first_order_date'].value.toInstant().toEpochMilli()) / params.factor",
        "params": {
          "factor": 86400000
        }
      }
    }
  }
}

4- Create new Cohort visualization, setup buckets :

  • set Cohort Date bucket: Aggregation - 'Date Histogram', Field - 'first_order_date', Interval - up to you;
  • set Cohort Period bucket: Sub Aggregation - 'Histogram', Field - 'dayUntilReturn', Minimum Interval - '0'

from kibana_cohort.

ylasri avatar ylasri commented on July 28, 2024

table
chart

from kibana_cohort.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.