# Terms facet on single field but also return associated id

**URL:** <https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170>\
**Category:** Elasticsearch\
**Created:** [January 9, 2014, 10:55am UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170 "2014-01-09T10:55:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_van\_der\_walt](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@Vincent\_van\_der\_walt](https://discuss.elastic.co/u/Vincent_van_der_walt)\
**Post date:** [January 9, 2014, 10:55am UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170/1 "2014-01-09T10:55:15Z")

</div>

Hi,

I'm wondering if anyone could help me.

We're doing a terms facet on a field which works fine. However I'm trying  
to also return the corresponding id of that field so I can provide click  
through functionality on my grid.

eg index = fieldid,fieldname

if I do a termsfacet I get

field1 10  
field2 34  
field3 50

but I'd like to return the id too rather than do another search and merge (  
very inefficient since I'm dealing with large amounts of data). Composite  
fields won't work for us since I'll have to constantly rebuild the index.  
the terms I'm using can be very dynamic.

Is this possible ?

Thanks

Vinny

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 14, 2014, 11:13am UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170/2 "2014-01-14T11:13:31Z")

</div>

Hey,

I am not sure I can follow your requirement. Cam you describe what you  
actually mean with an associated id? What is it associated with? A  
document? An index?

If you want to get the document ids, which actually were part of a facet  
bucket, this is not possible with facets and you might need to execute  
another query.

--Alex

On Thu, Jan 9, 2014 at 11:55 AM, Vincent van der walt \<  
[vincent.vanderwalt@gmail.com](mailto:vincent.vanderwalt@gmail.com)\> wrote:

> Hi,
> 
> I'm wondering if anyone could help me.
> 
> We're doing a terms facet on a field which works fine. However I'm trying  
> to also return the corresponding id of that field so I can provide click  
> through functionality on my grid.
> 
> eg index = fieldid,fieldname
> 
> if I do a termsfacet I get
> 
> field1 10  
> field2 34  
> field3 50
> 
> but I'd like to return the id too rather than do another search and merge  
> ( very inefficient since I'm dealing with large amounts of data). Composite  
> fields won't work for us since I'll have to constantly rebuild the index.  
> the terms I'm using can be very dynamic.
> 
> Is this possible ?
> 
> Thanks
> 
> Vinny
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-bjrdmxRgB-kZWg6Yk82HVKgvAa4ax\_Cz7uZdiCGbBDA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM-bjrdmxRgB-kZWg6Yk82HVKgvAa4ax_Cz7uZdiCGbBDA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Vincent\_van\_der\_walt](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@Vincent\_van\_der\_walt](https://discuss.elastic.co/u/Vincent_van_der_walt)\
**Post date:** [January 14, 2014, 12:39pm UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170/3 "2014-01-14T12:39:22Z")

</div>

Hi Alex

It's not the document id. There's 2 fields in the row for example

vinny, viking  
alexander, great

I would like to get the results for the terms facet and another field in  
the row

eg.

viking 1 (I also need vinny)  
great 1 (I also need alexander)

Does this makes sense ?

Vinny

On Tuesday, 14 January 2014 11:13:31 UTC, Alexander Reelsen wrote:

> Hey,
> 
> I am not sure I can follow your requirement. Cam you describe what you  
> actually mean with an associated id? What is it associated with? A  
> document? An index?
> 
> If you want to get the document ids, which actually were part of a facet  
> bucket, this is not possible with facets and you might need to execute  
> another query.
> 
> --Alex
> 
> On Thu, Jan 9, 2014 at 11:55 AM, Vincent van der walt \<  
> [vincent.v...@gmail.com](mailto:vincent.v...@gmail.com) \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I'm wondering if anyone could help me.
> > 
> > We're doing a terms facet on a field which works fine. However I'm trying  
> > to also return the corresponding id of that field so I can provide click  
> > through functionality on my grid.
> > 
> > eg index = fieldid,fieldname
> > 
> > if I do a termsfacet I get
> > 
> > field1 10  
> > field2 34  
> > field3 50
> > 
> > but I'd like to return the id too rather than do another search and merge  
> > ( very inefficient since I'm dealing with large amounts of data). Composite  
> > fields won't work for us since I'll have to constantly rebuild the index.  
> > the terms I'm using can be very dynamic.
> > 
> > Is this possible ?
> > 
> > Thanks
> > 
> > Vinny
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4f85c81c-c2c1-47c5-8dd8-c2894223f905%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4f85c81c-c2c1-47c5-8dd8-c2894223f905%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 14, 2014, 6:15pm UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170/4 "2014-01-14T18:15:27Z")

</div>

Just to clarify, when you say "there's 2 fields in the row", do you really  
mean that the field has two values (an array)? If so, the facet results  
should look like:

alexander 1  
great 1  
viking 1  
vinny 1

There is no easy way to achieve what you want. One way would be to great  
combined keys during your indexing process and create a new field to be  
faceted on. The values would be someting like alexander|great and  
viking|vinny. You would then need to process the results on the client side  
after your query.

What you perhaps really looking for is field collapsing, which is not yet  
supported. The elasticsearch team said it would be post 1.0.

Cheers,

Ivan

On Tue, Jan 14, 2014 at 4:39 AM, Vincent van der walt \<  
[vincent.vanderwalt@gmail.com](mailto:vincent.vanderwalt@gmail.com)\> wrote:

> Hi Alex
> 
> It's not the document id. There's 2 fields in the row for example
> 
> vinny, viking  
> alexander, great
> 
> I would like to get the results for the terms facet and another field in  
> the row
> 
> eg.
> 
> viking 1 (I also need vinny)  
> great 1 (I also need alexander)
> 
> Does this makes sense ?
> 
> Vinny
> 
> On Tuesday, 14 January 2014 11:13:31 UTC, Alexander Reelsen wrote:
> 
> > Hey,
> > 
> > I am not sure I can follow your requirement. Cam you describe what you  
> > actually mean with an associated id? What is it associated with? A  
> > document? An index?
> > 
> > If you want to get the document ids, which actually were part of a facet  
> > bucket, this is not possible with facets and you might need to execute  
> > another query.
> > 
> > --Alex
> > 
> > On Thu, Jan 9, 2014 at 11:55 AM, Vincent van der walt \<  
> > [vincent.v...@gmail.com](mailto:vincent.v...@gmail.com)\> wrote:
> > 
> > > Hi,
> > > 
> > > I'm wondering if anyone could help me.
> > > 
> > > We're doing a terms facet on a field which works fine. However I'm  
> > > trying to also return the corresponding id of that field so I can provide  
> > > click through functionality on my grid.
> > > 
> > > eg index = fieldid,fieldname
> > > 
> > > if I do a termsfacet I get
> > > 
> > > field1 10  
> > > field2 34  
> > > field3 50
> > > 
> > > but I'd like to return the id too rather than do another search and  
> > > merge ( very inefficient since I'm dealing with large amounts of data).  
> > > Composite fields won't work for us since I'll have to constantly rebuild  
> > > the index. the terms I'm using can be very dynamic.
> > > 
> > > Is this possible ?
> > > 
> > > Thanks
> > > 
> > > Vinny
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/4317dae0-690b-4205-a5f7-ea8e5908661d%  
> > > [40googlegroups.com](http://40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/4f85c81c-c2c1-47c5-8dd8-c2894223f905%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4f85c81c-c2c1-47c5-8dd8-c2894223f905%40googlegroups.com)  
> > .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAzCUsg7Jo60XdmOq1%3DiEtTkXeFOH8FmFBOt26HD%2Bf4Fg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAzCUsg7Jo60XdmOq1%3DiEtTkXeFOH8FmFBOt26HD%2Bf4Fg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:56am UTC](https://discuss.elastic.co/t/terms-facet-on-single-field-but-also-return-associated-id/15170/5 "2017-07-06T01:56:50Z")

</div>


