New feature request: Nested terms facets


(Lukáš Vlček) #1

Hi,

I am looking for a feature that would allow me to get nested terms facets
without prior knowledge of the values of the "parent" term.

Here is example:

Document has a two fields: category and subcategory. Providing that the
category has two values: 01 and 02 I can issue the following query:

{ "query":{"match_all":{}},
"facets":{
"category":{
"terms":{"field":"category","order":"term"}
},
"subcategory-for-category01":{
"terms":{"fields":["subcategory"],"order":"term"},
"facet_filter":{
"term":{"category":"01"}
}
},
"subcategory-for-categor02":{
"terms":{"fields":["subcategory"],"order":"term"},
"facet_filter":{
"term":{"category":"02"}
}
}
}
}

This returns the following facets:

{ "category": { "_type": "terms", "_field": "category", "terms": [ { "term":
"01", "count": 3 }, { "term": "02", "count": 4 } ] },
"subcategory-for-category01": { "_type": "terms", "_field": "subcategory",
"terms": [ { "term": "01", "count": 1 }, { "term": "02", "count": 2 } ] },
"subcategory-for-categor02": { "_type": "terms", "_field": "subcategory",
"terms": [ { "term": "01", "count": 2 }, { "term": "02", "count": 2 } ] } }

The problem is that this requires prior knowledge of category values. Would
it be possible to have this automated? Doing it on the client side (by
issuing an extra query to get category values in advance) is not very handy
and may not be data consistent.

Regards,
Lukas


(Lukáš Vlček) #2

An of course the query does not have to use "fields" terms facet for
subcategory, simple "filed" facet works fine as well :slight_smile:

{ "query":{"match_all":{}},
"facets":{
"category":{
"terms":{"field":"category","order":"term"}
},
"subcategory-for-category01":{
"terms":{"field":"subcategory","order":"term"},
"facet_filter":{
"term":{"category":"01"}
}
},
"subcategory-for-categor02":{
"terms":{"field":"subcategory","order":"term"},
"facet_filter":{
"term":{"category":"02"}
}
}
}
}

On Tue, Nov 2, 2010 at 11:34 PM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

Hi,

I am looking for a feature that would allow me to get nested terms facets
without prior knowledge of the values of the "parent" term.

Here is example:

Document has a two fields: category and subcategory. Providing that the
category has two values: 01 and 02 I can issue the following query:

{ "query":{"match_all":{}},
"facets":{
"category":{
"terms":{"field":"category","order":"term"}
},
"subcategory-for-category01":{
"terms":{"fields":["subcategory"],"order":"term"},
"facet_filter":{
"term":{"category":"01"}
}
},
"subcategory-for-categor02":{
"terms":{"fields":["subcategory"],"order":"term"},
"facet_filter":{
"term":{"category":"02"}
}
}
}
}

This returns the following facets:

{ "category": { "_type": "terms", "_field": "category", "terms": [ {
"term": "01", "count": 3 }, { "term": "02", "count": 4 } ] },
"subcategory-for-category01": { "_type": "terms", "_field": "subcategory",
"terms": [ { "term": "01", "count": 1 }, { "term": "02", "count": 2 } ] },
"subcategory-for-categor02": { "_type": "terms", "_field": "subcategory",
"terms": [ { "term": "01", "count": 2 }, { "term": "02", "count": 2 } ] } }

The problem is that this requires prior knowledge of category values. Would
it be possible to have this automated? Doing it on the client side (by
issuing an extra query to get category values in advance) is not very handy
and may not be data consistent.

Regards,
Lukas


(system) #3