I have documents which look like this (here are two examples):
{
"id": 1234,
"title": "the title",
"body": "the body",
"examples": [
{
"evidence_source": "friend",
"source_score": 15
},
{
"evidence_source": "parent",
"source_score": 12
}
]
}
and
{
"id": 6346,
"title": "new title",
"body": "lots of content",
"examples": [
{
"evidence_source": "friend",
"source_score": 10
},
{
"evidence_source": "parent",
"source_score": 27
},
{
"evidence_source": "child",
"source_score": 4
}
]
}
The format of the sub-documents in the examples array will always have an evidence_source and a source_score but there will be a variable amount of these sub-documents, each with different evidence_source values.
I am wondering if it is possible to sort documents with this format based on one of the source_score values matched to a specific evidence_source value. I'd really like to be able to do this:
- Sort documents by
source_scoredescending where the relatedevidence_sourceisfriend. The resulting ordering of the documentids would be 1234,6346. - Sort documents by
source_scoredescending where the relatedevidence_sourceisparent. The resulting ordering of the documentids would be 6346,1234.
The closest results that I'm come up with for doing something like this are 1 and 2 but I don't believe that they get at exactly what I want to do.
Any ideas about how I might go about this? I've contemplated some ideas based on indexing these examples sub-documents separately, but I'm fairly new to elasticsearch and so am looking for some advice on a how to achieve my goal in the most straightforward manner (which may be a pipe-dream...)
Update: A post on the elasticsearch mailing list seems to indicate that this is NOT possible, but I'm wondering if someone else here has any different ideas!