Returning only certain-values in facet search in multi-value field

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.)

Heya,

Did you look at Elasticsearch Platform — Find real-time answers at scale | Elastic ?
There's a section about Facet Filter.

Can this help you ?
HTH
David

Le 14 juin 2012 à 00:39, Matt Peach matthew.peach@mightyape.co.nz a écrit :

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.)

Sorry. Forget my answer.

Le 14 juin 2012 à 07:25, David Pilato david@pilato.fr a écrit :

Heya,

Did you look at Elasticsearch Platform — Find real-time answers at scale | Elastic ?
There's a section about Facet Filter.

Can this help you ?
HTH
David

Le 14 juin 2012 à 00:39, Matt Peach matthew.peach@mightyape.co.nz a écrit :

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.)