Implementation of a Complex Conditional Query

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?

This sounds as if the existing functionality when using the ip datatype supports the CIDR range queries that you are after.

1 Like