"titles" : ["one","duplicate","duplicate"] is a short form and becomes
"titles" : "one" and "titles":"duplicate" in the index.

With 'doc[]' scripts access the document in the indexed form, which is of
course not 1:1 with the source document. Maybe it works to use 'source[]'
 to access the source field in the index to get the original form, but be
warned, this is slow, because the whole source field must be loaded and
decoded for each document.

Jörg

On Fri, Jan 9, 2015 at 3:09 AM, Jeff Steinmetz <[email protected]>
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 your elasticsearch config for this to
> work.
>
> This was originally based on some comments I found here:
>
> http://stackoverflow.com/questions/17314123/search-by-size-of-object-type-field-elastic-search
>
> We would like to use a filtered query to only include documents that a
> small count of items in the list [aka array], filtering where
>  values.size() < 10
>
> "script": "doc['titles'].values.size() < 10"
>
> Turns out the values.size() actually either counts tokenized (analyzed)
> words, or if the mapping turns off analysis, it still counts incorrectly if
> there are duplicates.
> If analyze is not turned off, it counts tokenized words, not the number of
> elements in the list.
> If analyze is turned off for a given field, it improves, but duplicates
> are missed.
>
> For example, This comes back as size == 2
> "titles": ["one", "duplicate", "duplicate"]
> This comes back as size == 3, should be 4
> "titles": ["http://bit.ly/abc";, "http://bit.ly/abc";, "http://bit.ly/def";,
> "http://bit.ly/ghi";]
>
> Is this a bug, is there a better way, or is this just something that we
> don't understand about groovy and values.size()?
>
>
>
>
>
>
>
>
>
>
>  --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/f5e88338-8c4f-4cb8-b6c4-d7f47b365175%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/f5e88338-8c4f-4cb8-b6c4-d7f47b365175%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGtWd7c0zBDBvYtQ2j9F0%2ByKbJEPGSiFK5ni65kGHsAng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to