Time diffrence in painless script

Hi
i am trying to create Entity centric index by using painless script , i able to create entity index and upload data , but now i am trying to calculate time difference between two date .
my painless script looks like -

  //Copy doc source to local variable with shorter name
	def docSrc = ctx._source;

	if("create".equals(ctx.op)){
		//initialize entity state
		docSrc.Salesmans = [];
//		docSrc.profile = "newbie";
	}    
	
    // Convert seller array into map for ease of manipulation
    def SalesmanMap =[:];
    for (salesman in docSrc.Salesmans) {
      SalesmanMap[salesman.SalesmanCode]=salesman;
    }
    
    // Consolidate latest batch of events
    for (event in params.events) {
      def salesman =SalesmanMap[event.SalesmanCode];
      

        salesman=[
          "SalesmanCode": event.SalesmanCode,
		 "VisitStartTime": event.VisitStartDateTime,
		"VisitEndTime":event.VisitEndDateTime,
		"timespend":43
        ];
        SalesmanMap[salesman.SalesmanCode]=salesman;
	
    }
docSrc.Salesmans=SalesmanMap.values();
	
	docSrc.TimeinMarket = 100;

in the timespend column i need event.VisitStartDateTime - event.VisitEndDateTime into minute , but not able to get , any suggestion .
Thanks

You will need to parse the dates to do date math on them. The java time api is available in painless. Also note that you probably want end date minus start date (otherwise you would have a negative time).

thanks

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