Yes - I'm familiar with script sorting - this is my script for sorting
custom columns https://gist.github.com/3486870
Unfortunately, as the JavaDoc on the class explains each document needs it
own score and is totally unaware of other docs, so I can't do a Comparator
style sort. 32 or, effectively, 24 bits worth of float data does not go
very var when try to discriminate one string from all possible other
strings in the universe. In actual fact, for 2 column sorting I only got 2
letters from each column before running out of float numbers.
The Lucene Collector, from my brief look at the source code, that collects
the results from scripts is a ScoreDocCollector - which just gets the score
(a float) from each doc and sorts according to the score.
I really need to be able to compare each string to the other and sort the
docs using a comparator - or some equivalent map-reduce style comparator,
that will be able to compare one document's value to another.
When you say "Aren't you only getting ccID with a value of 520?" - the
answer, really is no. What I am effectively doing is doing an outer join
(equivalent to) on this value, so my results contains the value associated
with ccId=520, plus lots of other data, so I can't just use a nested
filter, because that will get rid of all my other data.
On Thursday, August 23, 2012 7:49:28 PM UTC+1, P Hill wrote:
On 8/23/2012 7:56 AM, davrob2 wrote:
I would like help in creating a plugin for sorting Nested properties,
There is one or zero occurrences of value (or ValueLC for sorting) for
each ccId per parent document.
So the process will be:
i) Do the search on other top level fields e.g. " fullName ".
ii) Sort the results according to the value associated a
particular ccId (0 or 1 per parent document)
In pseudo-code the process would be:
I haven't seen any sorting plugins, the nearest I have seen are
faceting plugins, any examples would be very welcome.
Since there are 5 shards per index, I can see this must be some kind
of map/reduce process to collect the sorted results from each shard,
then do a final sort.
I've been looking into various needs that include sorting. What I know
that I think is related is:
You can both sort on multiple fields and use a script to generate a
value to sort by.
see section "Script Based Sorting"
but as it says there using a custom_score_query can be quicker.
which can be used to generate just the right value to sort by, assuming
that would help.
In either case you can also register a Java "script", if you're not able
to tackle the problem of generating a special sort value with mval.
But what I see is query for documents where fullName=x and
I think your "nested where" must be an idea from SQL, I'm not enough of
an SQL expert to understand a where nested in a sort and how it differs
from just a general where for the selection or in ES case just in the
And I don't get what you mean when you specify ccId=520 and in #2 you
say you'll sort by that. Aren't you only getting ccID with a value of
520? I must be missing the use-case here.
Getting to the fields in a nested object is done with a nested query
which I haven't used.
But, if you just have one complex object, you can use path to it with
dots (which I find inadequately described on site), see
which include "name.first".
Is all of your document? If so, I might consider storing the _source,
so that you can use just use _source.custom.ccId, but I don't know if
this appropriate for you.
I don't store source myself, but that might be an option if you just
want to specify the field in a script_field