# Return docID instead of count in facets when count=1

**URL:** <https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699>\
**Category:** Elasticsearch\
**Created:** [November 13, 2012, 4:47pm UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699 "2012-11-13T16:47:36Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [November 13, 2012, 4:47pm UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699/1 "2012-11-13T16:47:36Z")

</div>

Heya,

I would like to create a new feature (pull request on existing code or plugin) and here is my use case:

Say I have 3 docs :  
id:1, color:red  
id:2, color:red  
id:3, color:yellow

If I run a MatchAllQuery with a TermFacet, I'll probably get:  
myfacet:  
term: red, count: 2  
term: yellow, count: 1

When my count is a very tiny number (say 1), I would like to get back their ids:  
myfacet:  
term: red, count: 2  
term: yellow, count: 1, ids:[1]

First: can I achieve this? Where can I start to hack ES code to code this.  
I was thinking of modifying TermsFacetBuilder to add an option (let's say idthreshold) but where should I use it after that?  
Is it a bad idea to think it as a facet feature?

Thanks for your insights.

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

--

---

<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:** [November 26, 2012, 1:54pm UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699/2 "2012-11-26T13:54:20Z")

</div>

Hi there,

Anyone has an idea about my use case?  
Is there any way to do it?

Thanks for any help (even if it's "you can not do it")  
David.

Le mardi 13 novembre 2012 17:47:40 UTC+1, David Pilato a écrit :

> Heya,
> 
> I would like to create a new feature (pull request on existing code or  
> plugin) and here is my use case:
> 
> Say I have 3 docs :  
> id:1, color:red  
> id:2, color:red  
> id:3, color:yellow
> 
> If I run a MatchAllQuery with a TermFacet, I'll probably get:  
> myfacet:  
> term: red, count: 2  
> term: yellow, count: 1
> 
> When my count is a very tiny number (say 1), I would like to get back  
> their ids:  
> myfacet:  
> term: red, count: 2  
> term: yellow, count: 1, ids:[1]
> 
> First: can I achieve this? Where can I start to hack ES code to code this.  
> I was thinking of modifying TermsFacetBuilder to add an option (let's say  
> idthreshold) but where should I use it after that?  
> Is it a bad idea to think it as a facet feature?
> 
> Thanks for your insights.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 26, 2012, 4:53pm UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699/3 "2012-11-26T16:53:45Z")

</div>

I would assume that the problem would be is that the reduce phase works  
over a map of keys and counts. You would need to pass around different a  
different, more complex data structure, between the nodes/shards.

--  
Ivan

On Mon, Nov 26, 2012 at 3:54 AM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Hi there,
> 
> Anyone has an idea about my use case?  
> Is there any way to do it?
> 
> Thanks for any help (even if it's "you can not do it")  
> David.
> 
> Le mardi 13 novembre 2012 17:47:40 UTC+1, David Pilato a écrit :
> 
> > Heya,
> > 
> > I would like to create a new feature (pull request on existing code or  
> > plugin) and here is my use case:
> > 
> > Say I have 3 docs :  
> > id:1, color:red  
> > id:2, color:red  
> > id:3, color:yellow
> > 
> > If I run a MatchAllQuery with a TermFacet, I'll probably get:  
> > myfacet:  
> > term: red, count: 2  
> > term: yellow, count: 1
> > 
> > When my count is a very tiny number (say 1), I would like to get back  
> > their ids:  
> > myfacet:  
> > term: red, count: 2  
> > term: yellow, count: 1, ids:[1]
> > 
> > First: can I achieve this? Where can I start to hack ES code to code  
> > this.  
> > I was thinking of modifying TermsFacetBuilder to add an option (let's say  
> > idthreshold) but where should I use it after that?  
> > Is it a bad idea to think it as a facet feature?
> > 
> > Thanks for your insights.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [December 23, 2012, 4:54pm UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699/4 "2012-12-23T16:54:27Z")

</div>

Hi ,

This is one feature i also would love to see.

Kindly comment on how to create a plugin for this purpose.

Thanks  
Vineeth

On Monday, November 26, 2012 10:23:50 PM UTC+5:30, Ivan Brusic wrote:

> I would assume that the problem would be is that the reduce phase works  
> over a map of keys and counts. You would need to pass around different a  
> different, more complex data structure, between the nodes/shards.
> 
> --  
> Ivan
> 
> On Mon, Nov 26, 2012 at 3:54 AM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)\<javascript:\>
> 
> > wrote:
> 
> > Hi there,
> > 
> > Anyone has an idea about my use case?  
> > Is there any way to do it?
> > 
> > Thanks for any help (even if it's "you can not do it")  
> > David.
> > 
> > Le mardi 13 novembre 2012 17:47:40 UTC+1, David Pilato a écrit :
> > 
> > > Heya,
> > > 
> > > I would like to create a new feature (pull request on existing code or  
> > > plugin) and here is my use case:
> > > 
> > > Say I have 3 docs :  
> > > id:1, color:red  
> > > id:2, color:red  
> > > id:3, color:yellow
> > > 
> > > If I run a MatchAllQuery with a TermFacet, I'll probably get:  
> > > myfacet:  
> > > term: red, count: 2  
> > > term: yellow, count: 1
> > > 
> > > When my count is a very tiny number (say 1), I would like to get back  
> > > their ids:  
> > > myfacet:  
> > > term: red, count: 2  
> > > term: yellow, count: 1, ids:[1]
> > > 
> > > First: can I achieve this? Where can I start to hack ES code to code  
> > > this.  
> > > I was thinking of modifying TermsFacetBuilder to add an option (let's  
> > > say idthreshold) but where should I use it after that?  
> > > Is it a bad idea to think it as a facet feature?
> > > 
> > > Thanks for your insights.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 24, 2012, 12:31am UTC](https://discuss.elastic.co/t/return-docid-instead-of-count-in-facets-when-count-1/9699/5 "2012-12-24T00:31:12Z")

</div>

For processing doc ids on the faceting level, the same prerequisites as for  
grouping results need to be implemented. I'm confident, after Lucene 4  
migration, changes to the faceting framework will enable fast multi-shard  
grouping and similar operations, also on plugin level.

For now, it's a big challenge, and must be patched into main codebase. No  
plugin hooks yet, afaik.

Jörg

--

---

<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/return-docid-instead-of-count-in-facets-when-count-1/9699/6 "2017-07-06T02:58:37Z")

</div>


