Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Nikolas Everett
On Thu, Jan 8, 2015 at 9:09 PM, Jeff Steinmetz jeffrey.steinm...@gmail.com wrote: Is there a better way to do this? Please see this gist (or even better yet, run the script locally see the issue). https://gist.github.com/jeffsteinmetz/2ea8329c667386c80fae You must have scripting enabled in

Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Nikolas Everett
Source is going to be pretty sloe, yeah. If its a one off then its probably fine but if you do it a lot probably best to index the count. On Jan 9, 2015 12:04 AM, Jeff Steinmetz jeffrey.steinm...@gmail.com wrote: Thank you, that worked. I was curious about the speed, is running a script using

Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Jeff Steinmetz
Now that I am into the real wold scenario, it gets a bit tricker - I have nested objects (keys). I have to test the existence of the key in the Groovy script to avoid parsing errors on insert. How do you access a nested object in groovy? and test for the existence of a nested object key? such

Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Jeff Steinmetz
Transform worked well. Nice. Curious how to get it to save to source? Tried this below, no go. (I can however do range queries agains title_count, so transform was indexed and works well) transform : { script : ctx._source['\'title_count\''] = ctx._source['\'titles\''].size(),

Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Jeff Steinmetz
Thank you, that worked. I was curious about the speed, is running a script using _source slower that doc[] ? Totally understand a dynamic script is slower regardless of _source vs doc[]. Makes sense that having a count transformed up front during index to create a materialized value would

Re: counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Nikolas Everett
Transform never saves to source. You have to transform on the application side for that. It was designed for times when you wanted to index something like this that would just take up extra space in the source document. I imagine you could use a script field on the query if you need the result to

counting items in a list [array] returns (what we think) are incorrect counts via groovy

2015-01-08 Thread Jeff Steinmetz
Is there a better way to do this? Please see this gist (or even better yet, run the script locally see the issue). https://gist.github.com/jeffsteinmetz/2ea8329c667386c80fae You must have scripting enabled in your elasticsearch config for this to work. This was originally based on some