# Perform some logic for query

**URL:** <https://discuss.elastic.co/t/perform-some-logic-for-query/196466>\
**Category:** Kibana\
**Created:** [August 23, 2019, 8:04am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466 "2019-08-23T08:04:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvtang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvtang/32/83160_2.png) [@kvtang](https://discuss.elastic.co/u/kvtang)\
**Post date:** [August 23, 2019, 8:04am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466/1 "2019-08-23T08:04:26Z")

</div>

Hi everyone,

I would like to ask that is it possible to query the data like one attribute MUST contain two different element. I can't find a better way to describe this so I'm going to give a simple example.

Let's say we have Alice, Bob, Charlie and David. And each of them buy different numbers of oranges and apples. So the data is like:-

- Alice, Orange
- Alice, Orange
- Alice, Apple
- Bob, Orange
- Charlie, Apple
- David, Orange
- David, Apple
- David, Apple

And I want to query that show the data whereby he/she MUST buy Orange AND Apple, and I'm expecting to see this result:

- Alice, Orange
- Alice, Orange
- Alice, Apple
- David, Orange
- David, Apple
- David, Apple

My end goal is to make a Horizontal Bar visualization on this whereby I have Alice and David on my Y axis, and split the chart into Orange and Apple, while showing the count of each data.

Thank you!

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [August 26, 2019, 10:17am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466/2 "2019-08-26T10:17:06Z")

</div>

Hi @kvtang,  
I think it's not possible right now using the standard interface of the Visualize Editor. I think you can add more logic using canvas and work on using the expression language to filter out "people" that doesn't have both Orange and Apple fruits on the created buckets

---

<div class="post-metadata">

**Author:** ![kvtang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvtang/32/83160_2.png) [@kvtang](https://discuss.elastic.co/u/kvtang)\
**Post date:** [September 4, 2019, 1:16am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466/3 "2019-09-04T01:16:19Z")

</div>

Hi @markov00,  
Can I know which is the exact feature I can use in canvas to add my logic there? Cause it seems that it is pretty much for customizing the visualization only.

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [September 16, 2019, 7:28am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466/4 "2019-09-16T07:28:47Z")

</div>

Hi @kvtang you can change the canvas expression to achieve that, piping together a set of canvas functions together: [https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html)

---

<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:** [October 14, 2019, 7:28am UTC](https://discuss.elastic.co/t/perform-some-logic-for-query/196466/5 "2019-10-14T07:28:52Z")

</div>

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