# Help making query

**URL:** <https://discuss.elastic.co/t/help-making-query/49293>\
**Category:** Elasticsearch\
**Created:** [May 5, 2016, 1:04pm UTC](https://discuss.elastic.co/t/help-making-query/49293 "2016-05-05T13:04:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vadiraj\_bidarahalli](https://avatars.discourse-cdn.com/v4/letter/v/7ea924/32.png) [@vadiraj\_bidarahalli](https://discuss.elastic.co/u/vadiraj_bidarahalli)\
**Post date:** [May 5, 2016, 1:04pm UTC](https://discuss.elastic.co/t/help-making-query/49293/1 "2016-05-05T13:04:01Z")

</div>

I have a document, pageTransition that has the following mapping.  
{  
"survale": {  
"mappings": {  
"pageTransition": {  
"properties": {  
"applicantCookie": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"clientId": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"cookie": {  
"type": "string"  
},  
"created": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"fromPageId": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"fromUrl": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"jobCookie": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"retryCounter": {  
"type": "long"  
},  
"toPageId": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"toUrl": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}

the records look like the following  
"hits": [  
{  
"\_index": "survale",  
"\_type": "pageTransition",  
"\_id": "AVMuRLqpRm51S9az\_qKD",  
"\_score": 1,  
"\_source": {  
"clientId": 0,  
"fromUrl": "[http://ats.survale.com/Apply/AdditionalInfo.aspx](http://ats.survale.com/Apply/AdditionalInfo.aspx)",  
"toUrl": "[http://ats.survale.com/Apply/ConfirmInfo.aspx](http://ats.survale.com/Apply/ConfirmInfo.aspx)",  
"fromPageId": "183",  
"toPageId": "184",  
"created": "2016-02-29T18:22:49.509Z"  
}  
},  
{  
"\_index": "survale",  
"\_type": "pageTransition",  
"\_id": "AVMuRKlGRm51S9az\_qKC",  
"\_score": 1,  
"\_source": {  
"clientId": 0,  
"fromUrl": "[http://ats.survale.com/Jobs/Default.aspx](http://ats.survale.com/Jobs/Default.aspx)",  
"toUrl": "[http://ats.survale.com/Apply/BasicInfo.aspx](http://ats.survale.com/Apply/BasicInfo.aspx)",  
"fromPageId": "177",  
"toPageId": "180",  
"created": "2016-02-29T18:22:45.047Z"  
}  
},  
{  
"\_index": "survale",  
"\_type": "pageTransition",  
"\_id": "AVMwO4dzRm51S9az\_qKH",  
"\_score": 1,  
"\_source": {  
"clientId": 0,  
"fromUrl": "[http://ats.survale.com/Login.aspx](http://ats.survale.com/Login.aspx)",  
"toUrl": "[http://ats.survale.com/jobs/](http://ats.survale.com/jobs/)",  
"fromPageId": "178",  
"toPageId": "185",  
"created": "2016-03-01T03:32:01.001Z"  
}  
},

say user reached from page 176 to page 177 at time t1. And from page 177 to page 180 at time t2. I am interested in the time t2-t1, which is the time user spent on page 177.  
there may be many records for page 177. I want to get all the times and then compute the average..  
Can someone advice me on how to approach?

Regards  
Vadiraj

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 6, 2016, 2:54am UTC](https://discuss.elastic.co/t/help-making-query/49293/2 "2016-05-06T02:54:10Z")

</div>

I think you would need to use a script to calculate this difference, then run the aggregation with that.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:53pm UTC](https://discuss.elastic.co/t/help-making-query/49293/3 "2017-07-05T22:53:28Z")

</div>

Closed on July 5, 2017, 10:53pm UTC


