# Doubt about complex query

**URL:** https://discuss.elastic.co/t/doubt-about-complex-query/245048
**Category:** Elasticsearch
**Created:** [August 14, 2020, 5:08pm UTC](https://discuss.elastic.co/t/doubt-about-complex-query/245048 "2020-08-14T17:08:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bgsouza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bgsouza/32/73902_2.png) [@bgsouza](https://discuss.elastic.co/u/bgsouza)
#### Post date: [August 14, 2020, 5:08pm UTC](https://discuss.elastic.co/t/doubt-about-complex-query/245048/1 "2020-08-14T17:08:22Z")

</div>

Hello everyone

I am a beginner in kibana and I'm having trouble setting up a query to generate a metric in Kibana. But I don't know if I'm structuring it wrong or if the query isn't even possible

**Giving a little context:**  
I have an email tracking system where I count on elasticsearch some values ​​such as: batch, userID, type, productId and a "maxItensInMail" which is the quantity of products recommended per batch / user  
And my goal is to set up a query that demonstrates the adherence of clicks on the products vs the recommended amount in the email

Today this data comes in a single field in the url format:  
site.com.br?lote=1234&userId=1&productId=567&type=recommendation-xpto&maxItensInMail=8

**Examples:**  
User = 1 opening 3 products from the lot = 1234 from an email containing 8 recommendations

Records in elasticsearch:  
1) site.com.br?lote=1234&userId=1&productId=567&type=recommendation-xpto&maxItensInMail=8  
2) site.com.br?lote=1234&userId=1&productId=8910&type=recommendation-xpto&maxItensInMail=8  
3) site.com.br?lote=1234&userId=1&productId=111213&type=recommendation-xpto&maxItensInMail=8

I can do a general query filtering by batch and algorithm but the problem I am facing now is how I get the unique hits by users (agg by batch & type) and divide it by "maxItensInMail" (which is a data that is repeated)

But my final goal is to use the return of this query to plot a bloxplot in the kibana using Vega

Does anyone have any suggestions on how I can proceed?

---

<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: [September 11, 2020, 5:08pm UTC](https://discuss.elastic.co/t/doubt-about-complex-query/245048/2 "2020-09-11T17:08:32Z")

</div>

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