# Elasticsearch querying time

**URL:** <https://discuss.elastic.co/t/elasticsearch-querying-time/247589>\
**Category:** Elasticsearch\
**Created:** [September 4, 2020, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589 "2020-09-04T19:23:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AditiKhalatkar](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@AditiKhalatkar](https://discuss.elastic.co/u/AditiKhalatkar)\
**Post date:** [September 4, 2020, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/1 "2020-09-04T19:23:54Z")

</div>

Hi all,

There is a use case, where I need some help from you guys. I wonder how should I do aggregation and which method would be the best.

Let's take an example. May be a school register.

Having 3 fields,  
student\_name, course\_taken, grade\_achieved, total\_pages. (this is index1) (\_id = student\_course)  
student\_name, course\_taken, course\_book, book\_page\_name (this is index2) (\_id = student\_course\_page)

I have 2 indices, each having 200,000 documents.  
Out of these 200,000, there is one redundant field say name. Its count is around 7K. I want to compute total\_pages of index1 out of index2.

Option 1:  
So shall I run an 7K aggregations on index2 to compute total pages?  
something like

> ```
> {
> "query":{
> "match":{
> //match student name
> //match course_taken
> // calculate number of pages
> }
> }
> }
> 
> ```

Also, this computation is per hour. So basically, updating index1, index2 and calculating total\_pages for 7K students each hour.

Option 2:  
I can create a hashmap in python to handle such aggregation on the raw document before ingesting it into elasticsearch, calculating total\_pages and inserting the answered data.

Which one should I go for?

Kindly guide. Thanks in advance!

---

<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:** [September 7, 2020, 12:21am UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/2 "2020-09-07T00:21:03Z")

</div>

To be clear, you want a total sum of `total_pages` for each individual `student_name`?

PS - We aren't all guys 🙂

---

<div class="post-metadata">

**Author:** ![AditiKhalatkar](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@AditiKhalatkar](https://discuss.elastic.co/u/AditiKhalatkar)\
**Post date:** [September 8, 2020, 12:40am UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/3 "2020-09-08T00:40:03Z")

</div>

Yes you are correct.

PS - Sorry about that! I take that back.

---

<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:** [September 8, 2020, 12:54am UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/4 "2020-09-08T00:54:41Z")

</div>

Thanks for clarifying!

You should be able to put together a terms aggregation on the name, and then sum the pages.

---

<div class="post-metadata">

**Author:** ![AditiKhalatkar](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@AditiKhalatkar](https://discuss.elastic.co/u/AditiKhalatkar)\
**Post date:** [September 8, 2020, 6:02pm UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/5 "2020-09-08T18:02:26Z")

</div>

Thanks for the reply. The blocker is these are 2 different indices, since terms aggregation works when 2 fields belong to the same index, I wonder how to include input from another index.

---

<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:** [October 6, 2020, 6:02pm UTC](https://discuss.elastic.co/t/elasticsearch-querying-time/247589/6 "2020-10-06T18:02:42Z")

</div>

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