Say I wanted to do a range facet on the image "size" property and group the
facets by book "id"
{
"book":{
"id": "1234",
"pages":[
{
"title": "elastic",
"images" : [
{
"name" : "some image",
"mimeType": "image/png",
"size", 100
},
{
"name" : "another image",
"mimeType": "image/png",
"size", 100
}
]
}
]
}
}
I have been trying this query
{
"from" : 0,
"size" : 1,
"query" : {
"query_string" : {
"query" : ":"
}
},
"explain" : true,
"facets" : {
"contentSize" : {
"range" : {
"key_script" : "doc['size']",
"value_script": "doc['id']",
"ranges" : [ {
"from" : 0.0,
"to" : 1048576.0
} ]
}
}
}
}
I don't think I clearly understand the 'value_script' property. I am
getting back the following exception,
Query Failed [Failed to execute main query]]; nested:
ClassCastException[org.elasticsearch.index.fielddata.ScriptDocValues$NumericLong
cannot be cast to java.lang.Number]; }
On Thursday, October 10, 2013 8:10:44 AM UTC+1, Alexander Reelsen wrote:
Hey,
range facets also support key_script and value_script parameters. There is
a simple example for the terms facet at
Elasticsearch Platform — Find real-time answers at scale | Elastic
Regarding key_script and value_script. It uses the key part for bucketing
and the value for the range statistics. Take this (artificial) example
"posts_tagging": {
"range" : {
"key_script" : "doc['release_date'].date.year",
"value_script" : "doc['tags'].size()",
"ranges" : [
{ "to" : 1970 },
{ "from" : 1970, "to" : 1990 },
{ "from" : 1990 }
]
}
}
You could actually get statistics if the posts which have a tags array and
a release date were more heavily tagged since 1990 onwards compared to
earlier days.
Hope this helps...
--Alex
On Wed, Oct 9, 2013 at 6:05 PM, dan <dan.t...@gmail.com <javascript:>>wrote:
Thanks Alex, could I use this with range facets too. Are there any
examples anywhere?
On Wednesday, October 9, 2013 4:34:03 PM UTC+1, Alexander Reelsen wrote:
Hey,
you could use the terms facet in combination with a script which
concatenates the fields together to create a unique. Obviously a bit slower
than doing this on indexing time, but maybe sufficient in your case...
Hope this helps.
--Alex
On Wed, Oct 9, 2013 at 4:57 PM, dan dan.t...@gmail.com wrote:
Is there a way to group a facet count based on another property. For
example, if my data looks like this:
{
"book":{
"id": "1234",
"pages":[
{
"title": "elastic",
"images" : [
{
"name" : "some image",
"mimeType": "image/png",
},
{
"name" : "another image",
"mimeType": "image/png",
}
]
}
]
}
}
and in my model I have made "pages" and "images" nested types.
I want to be able to facet on the 'mimeType' property of the images
within the pages of the book (i.e. book.pages.images.mimeType), but for my
example data above this will show a facet count of 2 for the 'image/png'
mime type. Is there any way to group these two facets based on another
property, i.e. book.id so that 'image/png' facet will only show only
show a count of 1?
--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearc...@**googlegroups.com.
For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.