From the comment back-and-forth I believe I understand what you want.
I.e.:
a record A
may be shown for every grade between minGrade
and maxGrade
.
For example:
a record 123
may be shown for every grade between minGrade = 2
and maxGrade = 6
.
Queries:
- for a given grade x, return all records for which
minGrade <= x <= maxGrade
- asked here I believe: for a given range on grade, say
[x1. x2]
, determine all records that have a non-empty overlap given their range[minGrade, maxGrade]
as follows:
- Given grade
x
(in pseudo code):minGrade <= x AND x <= maxGrade
You need to construct separate filter-facets for each bucket. e.g.: for
6-8
you could do either 1 of the following:(minGrade <= 6 AND 6 <= maxGrade) OR (minGrade <= 8 AND 8 <= maxGrade)
(6 <= minGrade AND minGrade <= 8) OR (6 <= maxGrade AND maxGrade <= 8)
2.2. could be implemented using 2 rangeQueries: 1 on mingrade
and 1 on maxgrade
combined with an OR
So an example 1 of filter facet could be (untested):
{
"facets": {
"grade_6-8": {
"filter": {
"or": [{
"range": {
"minGrade": {
"gte": 6,
"lte": 8
}
}
},
{
"range": {
"maxGrade": {
"gte": 6,
"lte": 8
}
}
}]
}
}
}
}
EDIT: the above is a:
- facet called
grade_6-8
- of type "filter facet"
- that contains a
or
- filter - which in turn contains 2 range filters . 1 for
minGrade
and 1 formaxGrade
. - NOTE You should repeat this for all the ranges you need separately
EDIT 2
when defining only 1 Grade
per document instead of minGrade
and maxGrade
the solution changes. It becomes possible to do this with a simple rangequery. Something like:
{
"query": {
"match_all": {}
},
"facets": {
"grade_ranges": {
"range": {
"field": "grade",
"ranges": [{
"to": 2
}, {
"from": 3,
"to": 5
}, {
"from": 6,
"to": 8
}, {
"from": 9,
"to": 12
}, {
"from": 13
}]
}
}
}
}
If this isn't what you're after please be more specific what you want.