# Help newbie: make dynamic aggregation by category

**URL:** https://discuss.elastic.co/t/help-newbie-make-dynamic-aggregation-by-category/62317
**Category:** Elasticsearch
**Created:** [October 5, 2016, 11:18pm UTC](https://discuss.elastic.co/t/help-newbie-make-dynamic-aggregation-by-category/62317 "2016-10-05T23:18:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Joomler](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Joomler](https://discuss.elastic.co/u/Joomler)
#### Post date: [October 5, 2016, 11:18pm UTC](https://discuss.elastic.co/t/help-newbie-make-dynamic-aggregation-by-category/62317/1 "2016-10-05T23:18:01Z")

</div>

I am new to Elasticsearch and try to learn it from docs.  
Now using Django-haystack 2.5.0 [https://django-haystack.readthedocs.io](https://django-haystack.readthedocs.io) and Elasticsearch 1.7.3

I need to implement dynamic facets: user have a form where he put  
names of facets, and after search is performed he is able to filter by  
these categories with sidebar filter form.

What i read in docs is facets implemented on fields, for example dates or authors, then filtering is done like this:

```
Tom (345)
Mary (218)
...

```

But this is not what i want. I have in my models only 1 text field and facets are aggregated dynamically during search.  
So, for movie texts i want facets like this:

```
Detective (633)
Comedy (237)
...

```

and each genre is calculated by search query:

Detective

text: \_"Columbo is an American television series starring Peter \_  
\_Falk as Columbo, a homicide detective with the Los Angeles Police \_  
\_Department.[2][3] The character and show, created by William Link and \_  
_Richard Levinson, popularized the inverted detective story format, which_  
\_ begins by showing the commission of the crime and its perpetrator; the \_  
_series therefore has no "whodunit" element. The plot revolves around how_  
\_ a perpetrator whose identity is already known to the audience will \_  
\_finally be caught and exposed (which the show's writers called a \_  
_"howcatchem," rather than a "whodunit")."_

to detect category Detective and Comedy we search:  
`(cop | murder | crime | ...) and (story | ...)`  
or  
`(joke| lol | ...) and (story | ...)`  
or  
....

And the same search strings for other categories - so i need big query at once with named parts  
I understand that explanations are unclear, but really not sure on what part of docs describe this.

1. Second question - i have read about term vectors to get list of words that found in text.  
How to setup this with Python's django-haystack lib? No such details in docs

---

<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 5, 2017, 10:14pm UTC](https://discuss.elastic.co/t/help-newbie-make-dynamic-aggregation-by-category/62317/2 "2017-07-05T22:14:21Z")

</div>


