Skip to content

Commit

Permalink
search dv only ip masks
Browse files Browse the repository at this point in the history
Signed-off-by: mikhail-khludnev <[email protected]>
  • Loading branch information
mikhail-khludnev committed Nov 13, 2024
1 parent 3d7184b commit bf572a8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,28 @@

- match: { hits.total: 2 }

- do:
search:
rest_total_hits_as_int: true
index: test-iodvq
body:
query:
term:
ip_field: "192.168.0.1/24"

- match: { hits.total: 3 }

- do:
search:
rest_total_hits_as_int: true
index: test-iodvq
body:
query:
term:
ip_field: "192.168.0.1/31"

- match: { hits.total: 1 }

- do:
search:
rest_total_hits_as_int: true
Expand Down Expand Up @@ -987,6 +1009,28 @@

- match: { hits.total: 2 }

- do:
search:
rest_total_hits_as_int: true
index: test-index
body:
query:
term:
ip_field: "192.168.0.1/24"

- match: { hits.total: 3 }

- do:
search:
rest_total_hits_as_int: true
index: test-index
body:
query:
term:
ip_field: "192.168.0.1/31"

- match: { hits.total: 1 }

- do:
search:
rest_total_hits_as_int: true
Expand Down Expand Up @@ -1516,6 +1560,28 @@

- match: { hits.total: 2 }

- do:
search:
rest_total_hits_as_int: true
index: test-doc-values
body:
query:
term:
ip_field: "192.168.0.1/31"

- match: { hits.total: 1 }

- do:
search:
rest_total_hits_as_int: true
index: test-doc-values
body:
query:
term:
ip_field: "192.168.0.1/24"

- match: { hits.total: 3 }

- do:
search:
rest_total_hits_as_int: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,14 @@ public Query termQuery(Object value, @Nullable QueryShardContext context) {
String term = value.toString();
if (term.contains("/")) {
final Tuple<InetAddress, Integer> cidr = InetAddresses.parseCidr(term);
return InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2());
PointRangeQuery pointsRange = (PointRangeQuery) InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2());
return SortedSetDocValuesField.newSlowRangeQuery(
name(),
new BytesRef(pointsRange.getLowerPoint()),
new BytesRef(pointsRange.getUpperPoint()),
true,
true
);
}
return SortedSetDocValuesField.newSlowExactQuery(name(), new BytesRef(((PointRangeQuery) query).getLowerPoint()));
}
Expand Down

0 comments on commit bf572a8

Please sign in to comment.