# Query to access distinct fields from different documents

**URL:** <https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493>\
**Category:** Elasticsearch\
**Created:** [February 9, 2017, 12:14pm UTC](https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493 "2017-02-09T12:14:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GautamP](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@GautamP](https://discuss.elastic.co/u/GautamP)\
**Post date:** [February 9, 2017, 12:14pm UTC](https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493/1 "2017-02-09T12:14:38Z")

</div>

Hi all,

I have two documents representing the start and end jobs of a batch respectively.

![](https://us1.discourse-cdn.com/elastic/original/2X/0/084fc673cab2b5d23026e3cde54070791ee9d361.png)

Here the field `p_job_name` represents the parent job and the field `job_name` represents the names of the sub jobs of the respective parent job. The fields `start` and `end` represent the start and end times of each job.

I want to calculate the complete batch time which would be `(End job).end - (Start job).start`.

When I use the script: `doc['end'].value - doc['start'].value`, I get the timings of the individual jobs (in minutes) which is shown in the `job_time` field.

I am unable to extract the end time of `End job` and the start time of `Start job` as part of a single query.

My aim is to obtain the overall batch time which would be : `596.683 mins`

Could you please help me out?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![GautamP](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@GautamP](https://discuss.elastic.co/u/GautamP)\
**Post date:** [February 10, 2017, 6:16am UTC](https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493/2 "2017-02-10T06:16:48Z")

</div>

I think I can solve this problem using the `logstash elapsed` plugin but I'm not able to install the plugin. I'll start a new topic in the logstash category.

---

<div class="post-metadata">

**Author:** ![mnozawa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mnozawa/32/15091_2.png) [@mnozawa](https://discuss.elastic.co/u/mnozawa)\
**Post date:** [February 10, 2017, 6:37am UTC](https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493/3 "2017-02-10T06:37:45Z")

</div>

Hi,

I think it is a kind of relationship issue.  
So this page may help you.  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/relations.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/relations.html)

---

<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:** [March 10, 2017, 6:38am UTC](https://discuss.elastic.co/t/query-to-access-distinct-fields-from-different-documents/74493/4 "2017-03-10T06:38:07Z")

</div>

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