Let's say this is the document indexed in elasticsearch:
{:id=>123,:a=>10, :b=>12,
:c=>[{:x=>A,:y=>102,:z=>92},{:x=>B,:y=>110,:z=>96},{:x=>C,:y=>94,:z=>106}]}
And I am firing some query to elasticsearch and it's guaranteed that this
will be the only document in the result set.
Is there a way to instruct elasticsearch that the array 'c' in the returned
document should be sorted on the basis of (y+3z).
Since the expression will be different every time, so I can't take care of
this while indexing.
If what you want is to sort the elements of the array within each
document, then I'm not sure how you can do it other than within your
application. I don't know of any way for changing the content of
results.
If you want to change the order of documents you get when you search,
based on the sum of the mentioned values, you might use a Custom Score
Query[0] or Script-based Sorting[2]. Something like this:
Although it would be slow for more results, because the script is
based on _source. I couldn't get it working with "doc"
Let's say this is the document indexed in elasticsearch:
{:id=>123,:a=>10, :b=>12,
:c=>[{:x=>A,:y=>102,:z=>92},{:x=>B,:y=>110,:z=>96},{:x=>C,:y=>94,:z=>106}]}
And I am firing some query to elasticsearch and it's guaranteed that this
will be the only document in the result set.
Is there a way to instruct elasticsearch that the array 'c' in the returned
document should be sorted on the basis of (y+3z).
Since the expression will be different every time, so I can't take care of
this while indexing.
If this is the only document and its source is stored, you can use
script_field to find and extract the element with the highest score.
Something like this:
On Wednesday, November 7, 2012 1:36:58 AM UTC-5, Azitabh Ajit wrote:
Let's say this is the document indexed in elasticsearch:
{:id=>123,:a=>10, :b=>12,
:c=>[{:x=>A,:y=>102,:z=>92},{:x=>B,:y=>110,:z=>96},{:x=>C,:y=>94,:z=>106}]}
And I am firing some query to elasticsearch and it's guaranteed that this
will be the only document in the result set.
Is there a way to instruct elasticsearch that the array 'c' in the
returned document should be sorted on the basis of (y+3z).
Since the expression will be different every time, so I can't take care of
this while indexing.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.