# Find contact with aggs terms and date range and use the found contacts for another aggs with date\_histogram

**URL:** <https://discuss.elastic.co/t/find-contact-with-aggs-terms-and-date-range-and-use-the-found-contacts-for-another-aggs-with-date-histogram/275762>\
**Category:** Elasticsearch\
**Created:** [June 13, 2021, 12:25pm UTC](https://discuss.elastic.co/t/find-contact-with-aggs-terms-and-date-range-and-use-the-found-contacts-for-another-aggs-with-date-histogram/275762 "2021-06-13T12:25:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregoire\_Tarres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregoire_tarres/32/90229_2.png) [@gregoire\_Tarres](https://discuss.elastic.co/u/gregoire_Tarres)\
**Post date:** [June 13, 2021, 12:25pm UTC](https://discuss.elastic.co/t/find-contact-with-aggs-terms-and-date-range-and-use-the-found-contacts-for-another-aggs-with-date-histogram/275762/1 "2021-06-13T12:25:13Z")

</div>

Hi, i'm new with Elaticsearch and I need some help for a search query.... Thanks in advance !

I've an index with docs between 2021-02-01 and 2021-04-01. I make a search query like this to retrieve phone numbers that appear between 2021-03-01 and 2021-03-02.

"aggs": {  
"timeseries": {  
"date\_range": {  
"field": "DateTime",  
"time\_zone": "CET",  
"format": "yyyy-MM-dd",  
"ranges": [ {  
"from": "2021-03-01",  
"to": "2021-03-02"  
}]  
},  
"aggs": {  
"PhoneNumber": {  
"terms": {  
"field": "Contact\_ID",  
"size": 10  
}

this works.

But now I want to make a date\_histogram aggregation with this found contacts but on all the period, that means from the 2021-02-01 to the 2021-04-01....

How can I realize this ??

Thanks a lot for your help !!!

---

<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 11, 2021, 12:26pm UTC](https://discuss.elastic.co/t/find-contact-with-aggs-terms-and-date-range-and-use-the-found-contacts-for-another-aggs-with-date-histogram/275762/2 "2021-07-11T12:26:09Z")

</div>

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