Mapping and sorting on array elements

Hello,

There is a sorting problem that I'm struggling with.

Let's say there are players that compete on an arbitrary number of tracks,
and who have a ranking on those tracks.
I want to query the results by track_id and get a list of the players that
competed on it, sorted by ranking.

The data that is mapped this way:

{
"results": {
"_source" : {"enabled": false},
"properties": {
"player": {"type": "string", "analyzer": "standard",
"omit_term_freq_and_positions": "true", "omit_norms": "true"},

        "tracks": {
            "type": "object",
            "properties": {
                "track_id" : {"type" : "integer"},
                "ranking" : {"type" : "integer"}
            }
        }
    }
}

}

What I'm doing now is querying for "tracks.track_id": 42, and sorting with
"sort":"tracks.ranking".
The problem is that if a player competed on more than one track,
ElasticSearch would pick its best value for "tracks.ranking" and sort using
that value. Obviously this brings wrong results.

How can I make it sort on the "tracks.ranking" value that corresponds to the
given "tracks.track_id" ?
Is there a better mapping for this need, or can this be solved with a
custom_score script?

Thanks in advance for any help on this problem.

--
Michel Valdrighi

Hi,

There isn't really a way to do it currently, even with custom_score
script. I have an idea on how to solve such "parent child" relationship, but
need some time to iron it out... .

-shay.banon

On Tue, Sep 28, 2010 at 11:49 AM, Michel Valdrighi michelv@gmail.comwrote:

Hello,

There is a sorting problem that I'm struggling with.

Let's say there are players that compete on an arbitrary number of tracks,
and who have a ranking on those tracks.
I want to query the results by track_id and get a list of the players that
competed on it, sorted by ranking.

The data that is mapped this way:

{
"results": {
"_source" : {"enabled": false},
"properties": {
"player": {"type": "string", "analyzer": "standard",
"omit_term_freq_and_positions": "true", "omit_norms": "true"},

        "tracks": {
            "type": "object",
            "properties": {
                "track_id" : {"type" : "integer"},
                "ranking" : {"type" : "integer"}
            }
        }
    }
}

}

What I'm doing now is querying for "tracks.track_id": 42, and sorting with
"sort":"tracks.ranking".
The problem is that if a player competed on more than one track,
Elasticsearch would pick its best value for "tracks.ranking" and sort using
that value. Obviously this brings wrong results.

How can I make it sort on the "tracks.ranking" value that corresponds to
the given "tracks.track_id" ?
Is there a better mapping for this need, or can this be solved with a
custom_score script?

Thanks in advance for any help on this problem.

--
Michel Valdrighi