Entity Centric index on two value

Hi i have one basic question ,
i am using entity centric index to create entity index for salesman my data look like -

"s1","salesman01","2017-06-22 00:00:00.000","2017-06-22 16:10:23.000","2017-06-22 16:11:44.000","5"
"s2","salesman01","2017-06-22 00:00:00.000","2017-06-22 17:10:23.000","2017-06-22 17:21:44.000","8"
"s3","salesman01","2017-06-22 00:00:00.000","2017-06-22 13:10:23.000","2017-06-22 14:11:44.000","7"
"s4","salesman01","2017-06-22 00:00:00.000","2017-06-22 12:10:23.000","2017-06-22 13:11:44.000","4"
"s5","salesman01","2017-06-22 00:00:00.000","2017-06-22 15:10:23.000","2017-06-22 16:10:44.000","2"
"s1","salesman01","2017-06-22 00:00:00.000","2017-06-22 20:10:23.000","2017-06-22 20:12:44.000","1"
"s2","salesman01","2017-06-22 00:00:00.000","2017-06-22 20:10:23.000","2017-06-22 21:21:44.000","3"
"s3","salesman01","2017-06-22 00:00:00.000","2017-06-22 19:10:23.000","2017-06-22 20:11:44.000","5"
"s4","salesman01","2017-06-22 00:00:00.000","2017-06-22 19:10:23.000","2017-06-22 20:11:44.000","8"
"s5","salesman01","2017-06-22 00:00:00.000","2017-06-22 21:10:23.000","2017-06-22 22:11:44.000","5"
"s1","salesman01","2017-06-23 00:00:00.000","2017-06-23 11:10:23.000","2017-06-23 12:11:44.000","5"
"s2","salesman01","2017-06-23 00:00:00.000","2017-06-23 12:10:23.000","2017-06-23 13:21:44.000","8"
"s3","salesman01","2017-06-23 00:00:00.000","2017-06-23 13:10:23.000","2017-06-23 14:11:44.000","7"
"s4","salesman01","2017-06-23 00:00:00.000","2017-06-23 14:10:23.000","2017-06-23 15:11:44.000","4"
"s5","salesman01","2017-06-23 00:00:00.000","2017-06-23 15:10:23.000","2017-06-23 16:10:44.000","2"
"s1","salesman01","2017-06-23 00:00:00.000","2017-06-23 16:10:23.000","2017-06-23 17:12:44.000","1"
"s2","salesman01","2017-06-23 00:00:00.000","2017-06-23 17:10:23.000","2017-06-23 18:21:44.000","3"
"s3","salesman01","2017-06-23 00:00:00.000","2017-06-23 18:10:23.000","2017-06-23 19:11:44.000","5"
"s4","salesman01","2017-06-23 00:00:00.000","2017-06-23 19:10:23.000","2017-06-23 20:11:44.000","8"
"s5","salesman01","2017-06-23 00:00:00.000","2017-06-23 20:10:23.000","2017-06-23 21:11:44.000","5"

my painless script -

  //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

//def sf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
def sf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");


//def dt1=sf1.parse("2017-06-22 15:12:00");
//def dt2 = sf1.parse("2017-06-24 15:15:00");

//def dtdif1=dt2.getTime()-dt1.getTime();


def minstarttime;
def  maxendtime;

    for (event in params.events) {

        def salesman =SalesmanMap[event.SalesmanCode];
	def datediff  =(sf2.parse(event.VisitEndDateTime).getTime()-sf2.parse(event.VisitStartDateTime).getTime()) / 60000;	
if(minstarttime ==null)
	{
	minstarttime=sf2.parse(event.VisitStartDateTime);
	maxendtime = sf2.parse(event.VisitEndDateTime);
docSrc.MinVisitStartTime = event.VisitStartDateTime;
docSrc.MaxVisitEndTime = event.VisitEndDateTime;

	}	

	if(salesman == null)
{	
        salesman=[
          "SalesmanCode": event.SalesmanCode,
	  "VisitDate": event.VisitDate,
          "timespend":datediff];
	

        SalesmanMap[salesman.SalesmanCode]=salesman;
}	else
{
salesman.timespend +=datediff;
}

if(minstarttime.getTime() > sf2.parse(event.VisitStartDateTime).getTime())
{
minstarttime= sf2.parse(event.VisitStartDateTime);
docSrc.MinVisitStartTime = event.VisitStartDateTime;

}
if(maxendtime.getTime() < sf2.parse(event.VisitEndDateTime).getTime())
{
maxendtime=sf2.parse(event.VisitEndDateTime);
docSrc.MaxVisitEndTime = event.VisitEndDateTime;

}
docSrc.VisitDate = event.VisitDate;
docSrc.TimeinMarket=salesman.timespend;


}    
docSrc.Salesmans=SalesmanMap.values();

but as per current script its create one record per salesman ,
now i wanted to create entity index salesman and date wise , means entity index should have record salemancode and date wise

one approach is i should create one extra field when uploading index with combination of salesman code and date and apply centric index on that .

there is any other way of doing this ?

thanks .

That would mean that the _id of your documents would need to be a concatenation of salesmanID and date.
Entity updates rely on providing the unique Elasticsearch ID of the document you want to update. I'm not sure what granularity you will choose to use for date (day? week? month?...) but you'll just need to format the date appropriately for that time unit e.g.the ID salesman01_2017-06-22

yes ,same we thought to merging both column and will create id column.
thanks for reply .

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