Hi all,
I'm running a facet query against a multi-valued field, and I'm wondering
whether it's possible to only return counts for certain values in the
field. (As opposed to counts for certain documents.)
So, for example, I have three documents as such:
document {
categories: [
1,
2,
3,
4
]
}
document {
categories: [
1,
99,
98,
97
]
}
document {
categories: [
2
]
}
From my testing, if I facet against the categories field with no filtering,
I will get an array as such:
[
{ "term" : "1", "count" : 2 },
{ "term" : "2", "count" : 2 },
{ "term" : "3", "count" : 1 },
{ "term" : "4", "count" : 1 },
{ "term" : "99", "count" : 1 },
{ "term" : "98", "count" : 1 },
{ "term" : "97", "count" : 1 },
{ "term" : "2", "count" : 1 }
]
I can also use a facet filter to only search documents that contain
category "1", which eliminates the "2" document:
[
{ "term" : "1", "count" : 2 },
{ "term" : "2", "count" : 1 },
{ "term" : "3", "count" : 1 },
{ "term" : "4", "count" : 1 },
{ "term" : "99", "count" : 1 },
{ "term" : "98", "count" : 1 },
{ "term" : "97", "count" : 1 }
]
What I'd like to do is only return counts for the values I care about; for
example, I want to know the counts for categories "1" and "2":
[
{ "term" : "1", "count" : 2 },
{ "term" : "2", "count" : 2 }
]
The rationale is that I already know exactly which categories my
application needs counts for, and want to reduce the response size of the
search. (My real-world example is returning counts for 200+ terms, and I
only need eight of them.)