Hierarchy Facet Script

Hi,
I have indexed documents with a multivalue field (MYFIELD)
on which I run the following query:

{
"query": {
"query_string": {
"query": ""
}
},
"facets": {
"MYFIELD_facet": {
"terms": {
"field": "MYFIELD",
"allterms": true,
* "script": "splitted = term.split('/'); return splitted[0];"

}
}
}
}

The query succeeded, however results are different than what I expected.
If a document contains values 'A/B' and 'A/C' for field MYFIELD it is
counted twice in the facet count!

facets: {
- MYFIELD_facet_H1: {
- _type: terms
- terms: [
- {
- term: A
- count: 2
}

I am now using ES 0.19, I need this feature for production soon (I am using
this trick to handle hierarchies).
Any help is appreciated! Thanks in advance

Lorenzo Melegari

You mean the same doc has A/B and A/C? Then yea, it will be counted twice
(not per doc, but per term).

On Wed, Apr 18, 2012 at 1:07 PM, Lorenzo Melegari <
lorenzo.melegari@gmail.com> wrote:

Hi,
I have indexed documents with a multivalue field (MYFIELD)
on which I run the following query:

{
"query": {
"query_string": {
"query": ""
}
},
"facets": {
"MYFIELD_facet": {
"terms": {
"field": "MYFIELD",
"allterms": true,
* "script": "splitted = term.split('/'); return splitted[0];"

}
}
}
}

The query succeeded, however results are different than what I expected.
If a document contains values 'A/B' and 'A/C' for field MYFIELD it is
counted twice in the facet count!

facets: {
- MYFIELD_facet_H1: {
- _type: terms
- terms: [
- {
- term: A
- count: 2
}

I am now using ES 0.19, I need this feature for production soon (I am
using this trick to handle hierarchies).
Any help is appreciated! Thanks in advance

Lorenzo Melegari