Skip to content

Commit ab4d5f4

Browse files
committed
Add overlapping, before, after filters to intervals query (#38999)
Lucene recently added `overlapping`, `before` and `after` filters to the intervals package. This commit exposes them in elasticsearch.
1 parent 2947ccf commit ab4d5f4

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

docs/reference/query-dsl/intervals-query.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,14 @@ Produces intervals that are contained by an interval from the filter rule
151151
Produces intervals that do not contain an interval from the filter rule
152152
`not_contained_by`::
153153
Produces intervals that are not contained by an interval from the filter rule
154+
`overlapping`::
155+
Produces intervals that overlap with an interval from the filter rule
154156
`not_overlapping`::
155157
Produces intervals that do not overlap with an interval from the filter rule
158+
`before`::
159+
Produces intervals that appear before an interval from the filter role
160+
`after`::
161+
Produces intervals that appear after an interval from the filter role
156162

157163
[[interval-script-filter]]
158164
==== Script filters

rest-api-spec/src/main/resources/rest-api-spec/test/search/230_interval_query.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,68 @@ setup:
322322
query: "there"
323323
ordered: false
324324
- match: { hits.total.value: 1 }
325+
326+
---
327+
"Test overlapping":
328+
- skip:
329+
version: " - 7.9.99"
330+
reason: "Implemented in 7.1"
331+
- do:
332+
search:
333+
index: test
334+
body:
335+
query:
336+
intervals:
337+
text:
338+
match:
339+
query: "cold outside"
340+
ordered: true
341+
filter:
342+
overlapping:
343+
match:
344+
query: "baby there"
345+
ordered: false
346+
- match: { hits.total.value: 1 }
347+
- match: { hits.hits.0._id: "3" }
348+
349+
---
350+
"Test before":
351+
- skip:
352+
version: " - 7.9.99"
353+
reason: "Implemented in 7.1"
354+
- do:
355+
search:
356+
index: test
357+
body:
358+
query:
359+
intervals:
360+
text:
361+
match:
362+
query: "cold"
363+
filter:
364+
before:
365+
match:
366+
query: "outside"
367+
- match: { hits.total.value: 2 }
368+
369+
---
370+
"Test after":
371+
- skip:
372+
version: " - 7.9.99"
373+
reason: "Implemented in 7.1"
374+
- do:
375+
search:
376+
index: test
377+
body:
378+
query:
379+
intervals:
380+
text:
381+
match:
382+
query: "cold"
383+
filter:
384+
after:
385+
match:
386+
query: "outside"
387+
- match: { hits.total.value: 1 }
388+
- match: { hits.hits.0._id: "4" }
389+

server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,14 @@ public IntervalsSource filter(IntervalsSource input, QueryShardContext context,
453453
return Intervals.notContaining(input, filterSource);
454454
case "not_contained_by":
455455
return Intervals.notContainedBy(input, filterSource);
456+
case "overlapping":
457+
return Intervals.overlapping(input, filterSource);
456458
case "not_overlapping":
457459
return Intervals.nonOverlapping(input, filterSource);
460+
case "before":
461+
return Intervals.before(input, filterSource);
462+
case "after":
463+
return Intervals.after(input, filterSource);
458464
default:
459465
throw new IllegalArgumentException("Unknown filter type [" + type + "]");
460466
}

server/src/test/java/org/elasticsearch/index/query/IntervalQueryBuilderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public void testUnknownField() throws IOException {
5353
}
5454

5555
private static final String[] filters = new String[]{
56-
"containing", "contained_by", "not_containing", "not_contained_by", "not_overlapping"
56+
"containing", "contained_by", "not_containing", "not_contained_by",
57+
"overlapping", "not_overlapping", "before", "after"
5758
};
5859

5960
private IntervalsSourceProvider.IntervalFilter createRandomFilter() {

0 commit comments

Comments
 (0)