# Implementation of a Complex Conditional Query

**URL:** <https://discuss.elastic.co/t/implementation-of-a-complex-conditional-query/218909>\
**Category:** Elasticsearch\
**Created:** [February 12, 2020, 6:51am UTC](https://discuss.elastic.co/t/implementation-of-a-complex-conditional-query/218909 "2020-02-12T06:51:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AkankshaKunwar](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@AkankshaKunwar](https://discuss.elastic.co/u/AkankshaKunwar)\
**Post date:** [February 12, 2020, 6:51am UTC](https://discuss.elastic.co/t/implementation-of-a-complex-conditional-query/218909/1 "2020-02-12T06:51:52Z")

</div>

Hello Everyone , I am new to the implementation of such complex query and need help, Kindly do the favour.

In our Database we have documnets having IP address as a field ( with other additional information), Now I want to fetch all the IP addresses that belongs to some particular IP address pool (that I will provide).

For Example : Input pool = 192.168.144.0/20  
Now I have different IPs in our database like 192.168.145.0, 192.168.146.0, 192.168.143.0 , So I want to filter these IPs 192.168.145.0, 192.168.146.0 beacause these IPs belongs to my desired IP pool.  
As per our approach,  
**RESULT = (INPUT\_POOL) & (IP\_IN\_DOCUMENT) == (INPUT\_POOL)**  
RESULT should be true of ip belongs to the pool else false.

So now is there any type of query through which we can implement this type of complex approach  
for ex: In bool query:  
{  
"match\_phrase":{  
RESULT:{  
"query":true  
}  
}  
}  
so as you can see in place of "field" parameter i used a conditional statement.

Is there any other approach to implement this kind of query or please do tell us that are we going in right direction?

---

<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:** [February 12, 2020, 4:12pm UTC](https://discuss.elastic.co/t/implementation-of-a-complex-conditional-query/218909/2 "2020-02-12T16:12:41Z")

</div>

This sounds as if the existing functionality when using the [ip datatype](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/ip.html) supports the CIDR range queries that you are after.

---

<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:** [March 11, 2020, 4:12pm UTC](https://discuss.elastic.co/t/implementation-of-a-complex-conditional-query/218909/3 "2020-03-11T16:12:42Z")

</div>

Closed on March 11, 2020, 4:12pm UTC

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