Can I group facet counts?


(Dan Tuffery) #1

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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Alexander Reelsen) #2

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.tuffery@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 elasticsearch+unsubscribe@googlegroups.com.
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.


(Dan Tuffery) #3

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 <javascript:>>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 <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.


(Alexander Reelsen) #4

Hey,

range facets also support key_script and value_script parameters. There is
a simple example for the terms facet at
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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.tuffery@gmail.com 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 elasticsearch+unsubscribe@googlegroups.com.
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.


(Dan Tuffery) #5

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
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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.


(Alexander Reelsen) #6

Hey,

use doc['size'].value and doc['id'].value instead and see if it works.

--Alex

On Thu, Oct 10, 2013 at 5:28 PM, dan dan.tuffery@gmail.com wrote:

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 http://www.elasticsearch.**
org/guide/en/elasticsearch/reference/current/search-
facets-terms-facet.htmlhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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 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.
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 elasticsearch+unsubscribe@googlegroups.com.
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.


(Dan Tuffery) #7

Slightly different exception:

nested: ClassCastException[java.lang.String cannot be cast to
java.lang.Number]

On Thursday, October 10, 2013 4:49:17 PM UTC+1, Alexander Reelsen wrote:

Hey,

use doc['size'].value and doc['id'].value instead and see if it works.

--Alex

On Thu, Oct 10, 2013 at 5:28 PM, dan <dan.t...@gmail.com <javascript:>>wrote:

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 http://www.elasticsearch.**
org/guide/en/elasticsearch/reference/current/search-
facets-terms-facet.htmlhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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


(Alexander Reelsen) #8

Hey,

is your data of the field maybe stored as a string instead of a number in
the mapping? (Use the GET Mapping API to find out)...

--Alex

On Thu, Oct 10, 2013 at 5:55 PM, dan dan.tuffery@gmail.com wrote:

Slightly different exception:

nested: ClassCastException[java.lang.String cannot be cast to
java.lang.Number]

On Thursday, October 10, 2013 4:49:17 PM UTC+1, Alexander Reelsen wrote:

Hey,

use doc['size'].value and doc['id'].value instead and see if it works.

--Alex

On Thu, Oct 10, 2013 at 5:28 PM, dan dan.t...@gmail.com wrote:

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 http://www.elasticsearch.**
or**g/guide/en/elasticsearch/reference/current/search-facets-
terms-facet.htmlhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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 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/grou**
ps/opt_out 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 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.
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 elasticsearch+unsubscribe@googlegroups.com.
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.


(Dan Tuffery) #9

Yes, the ID is a String and I can't change that, will the script only work
on a number?

On Friday, October 11, 2013 7:28:54 AM UTC+1, Alexander Reelsen wrote:

Hey,

is your data of the field maybe stored as a string instead of a number in
the mapping? (Use the GET Mapping API to find out)...

--Alex

On Thu, Oct 10, 2013 at 5:55 PM, dan <dan.t...@gmail.com <javascript:>>wrote:

Slightly different exception:

nested: ClassCastException[java.lang.String cannot be cast to
java.lang.Number]

On Thursday, October 10, 2013 4:49:17 PM UTC+1, Alexander Reelsen wrote:

Hey,

use doc['size'].value and doc['id'].value instead and see if it works.

--Alex

On Thu, Oct 10, 2013 at 5:28 PM, dan dan.t...@gmail.com wrote:

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
http://www.elasticsearch.org/guide/en/elasticsearch/refer
ence/current/search-**facets-**terms-facet.htmlhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html

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 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/grou**
ps/opt_out 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 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.
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.


(system) #10