# How can I get N document from each facet

**URL:** <https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149>\
**Category:** Elasticsearch\
**Created:** [December 21, 2012, 9:39am UTC](https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149 "2012-12-21T09:39:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chunki\_Calvin\_Lee\_2](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@Chunki\_Calvin\_Lee\_2](https://discuss.elastic.co/u/Chunki_Calvin_Lee_2)\
**Post date:** [December 21, 2012, 9:39am UTC](https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149/1 "2012-12-21T09:39:42Z")

</div>

Is there any way to get N document?

What I am doing is

1. query with "facets"
2. get facet list
3. looping and get document

How can I get the data with one query request?

Thanks.

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 21, 2012, 10:36am UTC](https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149/2 "2012-12-21T10:36:08Z")

</div>

What I will probably do is to send 2 calls:  
1 - facet computation  
2 - multisearch query for each term or a Terms Query with an array of facet terms as parameter.

I can't see a way to do it with only one call.

FYI, I need also to get a list of documents matching a Facet when number of docs is small (less than 10 for example) and I'm still digging into the source code to see if it's possible or not to get it with only one call.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 21 déc. 2012 à 10:39, Chunki Calvin Lee [lck7141@widerplanet.com](mailto:lck7141@widerplanet.com) a écrit :

> Is there any way to get N document?
> 
> What I am doing is
> 
> 1. query with "facets"
> 2. get facet list
> 3. looping and get document
> 
> How can I get the data with one query request?
> 
> ## Thanks.

--

---

<div class="post-metadata">

**Author:** ![Chunki\_Calvin\_Lee\_2](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@Chunki\_Calvin\_Lee\_2](https://discuss.elastic.co/u/Chunki_Calvin_Lee_2)\
**Post date:** [December 21, 2012, 11:35am UTC](https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149/3 "2012-12-21T11:35:42Z")

</div>

Thanks for your answer.

Unfortunately, I am using php so I can not run multi search query.  
whenever I use php's curl function, elasticsearch returns first query's  
result.

2012년 12월 21일 금요일 오후 7시 36분 8초 UTC+9, David Pilato 님의 말:

> What I will probably do is to send 2 calls:  
> 1 - facet computation  
> 2 - multisearch query for each term or a Terms Query with an array of  
> facet terms as parameter.
> 
> I can't see a way to do it with only one call.
> 
> FYI, I need also to get a list of documents matching a Facet when number  
> of docs is small (less than 10 for example) and I'm still digging into the  
> source code to see if it's possible or not to get it with only one call.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 21 déc. 2012 à 10:39, Chunki Calvin Lee \<[lck...@widerplanet.com](mailto:lck...@widerplanet.com)\<javascript:\>\>  
> a écrit :
> 
> Is there any way to get N document?
> 
> What I am doing is
> 
> 1. query with "facets"
> 2. get facet list
> 3. looping and get document
> 
> How can I get the data with one query request?
> 
> Thanks.
> 
> --

--

---

<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 6, 2017, 2:58am UTC](https://discuss.elastic.co/t/how-can-i-get-n-document-from-each-facet/10149/4 "2017-07-06T02:58:47Z")

</div>

Closed on July 6, 2017, 2:58am UTC


