Skip to content

Commit af0b507

Browse files
[DOCS] Interval query max_gaps in all_of rule (#119963) (#119998)
Add more explanation how `max_gaps` work in interval queries with `all_of` rule. Closes #113554
1 parent 940ad90 commit af0b507

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

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

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,22 @@ matches. Defaults to `-1`.
303303

304304
If unspecified or set to `-1`, there is no width restriction on the match. If
305305
set to `0`, the terms must appear next to each other.
306+
307+
Internal intervals can have their own `max_gaps` values. In this case
308+
we first find internal intervals with their `max_gaps` values, and then
309+
combine them to see if a gap between internal intervals match
310+
the value of `max_gaps` of the `all_of` rule.
311+
312+
For examples, how `max_gaps` works, see <<interval-max_gaps-all-rule>>.
306313
--
307314

308315
`ordered`::
309316
(Optional, Boolean) If `true`, intervals produced by the rules should appear in
310317
the order in which they are specified. Defaults to `false`.
311318

319+
If `ordered` is `false`, intervals can appear in any order,
320+
including overlapping with each other.
321+
312322
`filter`::
313323
(Optional, <<interval_filter,interval filter>> rule object) Rule used to filter
314324
returned intervals.
@@ -468,3 +478,94 @@ This query does *not* match a document containing the phrase `hot porridge is
468478
salty porridge`, because the intervals returned by the match query for `hot
469479
porridge` only cover the initial two terms in this document, and these do not
470480
overlap the intervals covering `salty`.
481+
482+
[[interval-max_gaps-all-rule]]
483+
===== max_gaps in `all_of` ordered and unordered rule
484+
485+
The following `intervals` search returns documents containing `my
486+
favorite food` without any gap, followed by `cold porridge` that
487+
can have at most 4 tokens between "cold" and "porridge". These
488+
two inner intervals when combined in the outer `all_of` interval,
489+
must have at most 1 gap between each other.
490+
491+
Because the `all_of` rule has `ordered` set to `true`, the inner
492+
intervals are expected to be in the provided order. Thus,
493+
this search would match a `my_text` value of `my favorite food is cold
494+
porridge` but not `when it's cold my favorite food is porridge`.
495+
496+
[source,console]
497+
--------------------------------------------------
498+
POST _search
499+
{
500+
"query": {
501+
"intervals" : {
502+
"my_text" : {
503+
"all_of" : {
504+
"ordered" : true, <1>
505+
"max_gaps": 1,
506+
"intervals" : [
507+
{
508+
"match" : {
509+
"query" : "my favorite food",
510+
"max_gaps" : 0,
511+
"ordered" : true
512+
}
513+
},
514+
{
515+
"match" : {
516+
"query" : "cold porridge",
517+
"max_gaps" : 4,
518+
"ordered" : true
519+
}
520+
}
521+
]
522+
}
523+
}
524+
}
525+
}
526+
}
527+
--------------------------------------------------
528+
<1> The `ordered` parameter is set to `true`, so intervals must appear in the order specified.
529+
530+
531+
Below is the same query, but with `ordered` set to `false`. This means that
532+
intervals can appear in any order, even overlap with each other.
533+
Thus, this search would match a `my_text` value of `my favorite food is cold
534+
porridge`, as well as `when it's cold my favorite food is porridge`.
535+
In `when it's cold my favorite food is porridge`, `cold .... porridge` interval
536+
overlaps with `my favorite food` interval.
537+
538+
[source,console]
539+
--------------------------------------------------
540+
POST _search
541+
{
542+
"query": {
543+
"intervals" : {
544+
"my_text" : {
545+
"all_of" : {
546+
"ordered" : false, <1>
547+
"max_gaps": 1,
548+
"intervals" : [
549+
{
550+
"match" : {
551+
"query" : "my favorite food",
552+
"max_gaps" : 0,
553+
"ordered" : true
554+
}
555+
},
556+
{
557+
"match" : {
558+
"query" : "cold porridge",
559+
"max_gaps" : 4,
560+
"ordered" : true
561+
}
562+
}
563+
]
564+
}
565+
}
566+
}
567+
}
568+
}
569+
--------------------------------------------------
570+
<1> The `ordered` parameter is set to `true`, so intervals can appear in any order,
571+
even overlap with each other.

0 commit comments

Comments
 (0)