nmosafi
(nmosafi)
January 17, 2011, 11:43pm
1
Hi there
I am trying to use the multi field terms facet. Say I have documents
which look like this:
{
"fruit": "apple",
"colour": "green",
"size": "large"
},
{
"fruit": "banana",
"colour": "yellow",
"size": "large"
},
{
"fruit": "grape",
"colour": "green",
"size": "small"
}
and I run a multi terms facet:
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "fields" : ["colour",
"size"] } } }
}
Here I am trying to get three facets to be returned
{"terms": [ "green", "large" ], "count": 1 }
{"terms": [ "yellow", "large" ], "count": 1 }
{"terms": [ "green", "small" ], "count": 1 }
However I get back this
{"term": "green", "count": 2 }
{"term": "yellow", "count": 1 }
{"term": "large", "count": 2 }
{"term": "small", "count": 1 }
Is there a way to achieve what I am trying?
kimchy
(Shay Banon)
January 18, 2011, 12:22am
2
there is no support for hierarchal facet (yet) in elasticsearch.
On Tuesday, January 18, 2011 at 1:43 AM, Neil Mosafi wrote:
Hi there
I am trying to use the multi field terms facet. Say I have documents
which look like this:
{
"fruit": "apple",
"colour": "green",
"size": "large"
},
{
"fruit": "banana",
"colour": "yellow",
"size": "large"
},
{
"fruit": "grape",
"colour": "green",
"size": "small"
}
and I run a multi terms facet:
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "fields" : ["colour",
"size"] } } }
}
Here I am trying to get three facets to be returned
{"terms": [ "green", "large" ], "count": 1 }
{"terms": [ "yellow", "large" ], "count": 1 }
{"terms": [ "green", "small" ], "count": 1 }
However I get back this
{"term": "green", "count": 2 }
{"term": "yellow", "count": 1 }
{"term": "large", "count": 2 }
{"term": "small", "count": 1 }
Is there a way to achieve what I am trying?
nmosafi
(nmosafi)
January 18, 2011, 10:11am
3
Just come up with a solution
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "script_field" : "_source.colour +
',' + _source.size" } } }
}
Seems to work, obviously assumes that there are no commas in the data.
Let me know if this is a bad idea? The docs say it's slow and has high
load.
On Jan 18, 12:22 am, Shay Banon shay.ba...@elasticsearch.com wrote:
there is no support for hierarchal facet (yet) in elasticsearch.
On Tuesday, January 18, 2011 at 1:43 AM, Neil Mosafi wrote:
Hi there
I am trying to use the multi field terms facet. Say I have documents
which look like this:
{
"fruit": "apple",
"colour": "green",
"size": "large"
},
{
"fruit": "banana",
"colour": "yellow",
"size": "large"
},
{
"fruit": "grape",
"colour": "green",
"size": "small"
}
and I run a multi terms facet:
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "fields" : ["colour",
"size"] } } }
}
Here I am trying to get three facets to be returned
{"terms": [ "green", "large" ], "count": 1 }
{"terms": [ "yellow", "large" ], "count": 1 }
{"terms": [ "green", "small" ], "count": 1 }
However I get back this
{"term": "green", "count": 2 }
{"term": "yellow", "count": 1 }
{"term": "large", "count": 2 }
{"term": "small", "count": 1 }
Is there a way to achieve what I am trying?
kimchy
(Shay Banon)
January 18, 2011, 10:14am
4
It will be slower compared to a native solution, but might be good for what you do. Make sure to use the doc notation, not the _source (so the source will not be loaded and parsed, but values will be loaded and used from memory), for example:
doc['colour'].value + doc['size'].value
-shay.banon
On Tuesday, January 18, 2011 at 12:11 PM, Neil Mosafi wrote:
Just come up with a solution
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "script_field" : "_source.colour +
',' + _source.size" } } }
}
Seems to work, obviously assumes that there are no commas in the data.
Let me know if this is a bad idea? The docs say it's slow and has high
load.
On Jan 18, 12:22 am, Shay Banon shay.ba...@elasticsearch.com wrote:
there is no support for hierarchal facet (yet) in elasticsearch.
On Tuesday, January 18, 2011 at 1:43 AM, Neil Mosafi wrote:
Hi there
I am trying to use the multi field terms facet. Say I have documents
which look like this:
{
"fruit": "apple",
"colour": "green",
"size": "large"
},
{
"fruit": "banana",
"colour": "yellow",
"size": "large"
},
{
"fruit": "grape",
"colour": "green",
"size": "small"
}
and I run a multi terms facet:
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "fields" : ["colour",
"size"] } } }
}
Here I am trying to get three facets to be returned
{"terms": [ "green", "large" ], "count": 1 }
{"terms": [ "yellow", "large" ], "count": 1 }
{"terms": [ "green", "small" ], "count": 1 }
However I get back this
{"term": "green", "count": 2 }
{"term": "yellow", "count": 1 }
{"term": "large", "count": 2 }
{"term": "small", "count": 1 }
Is there a way to achieve what I am trying?
nmosafi
(nmosafi)
January 18, 2011, 1:33pm
5
Great, it's working well.
Thanks for the help!
Neil
On Jan 18, 10:14 am, Shay Banon shay.ba...@elasticsearch.com wrote:
It will be slower compared to a native solution, but might be good for what you do. Make sure to use the doc notation, not the _source (so the source will not be loaded and parsed, but values will be loaded and used from memory), for example:
doc['colour'].value + doc['size'].value
-shay.banon
On Tuesday, January 18, 2011 at 12:11 PM, Neil Mosafi wrote:
Just come up with a solution
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "script_field" : "_source.colour +
',' + _source.size" } } }
}
Seems to work, obviously assumes that there are no commas in the data.
Let me know if this is a bad idea? The docs say it's slow and has high
load.
On Jan 18, 12:22 am, Shay Banon shay.ba...@elasticsearch.com wrote:
there is no support for hierarchal facet (yet) in elasticsearch.
On Tuesday, January 18, 2011 at 1:43 AM, Neil Mosafi wrote:
Hi there
I am trying to use the multi field terms facet. Say I have documents
which look like this:
{
"fruit": "apple",
"colour": "green",
"size": "large"
},
{
"fruit": "banana",
"colour": "yellow",
"size": "large"
},
{
"fruit": "grape",
"colour": "green",
"size": "small"
}
and I run a multi terms facet:
{
"query": { "match_all": {} },
"size": 0,
"facets": { "myFacet": { "terms": { "fields" : ["colour",
"size"] } } }
}
Here I am trying to get three facets to be returned
{"terms": [ "green", "large" ], "count": 1 }
{"terms": [ "yellow", "large" ], "count": 1 }
{"terms": [ "green", "small" ], "count": 1 }
However I get back this
{"term": "green", "count": 2 }
{"term": "yellow", "count": 1 }
{"term": "large", "count": 2 }
{"term": "small", "count": 1 }
Is there a way to achieve what I am trying?