Hi, is there a way in elasticsearch to "fallback" on a default field value when sorting on a missing field?
For instance, let assume I have a field A and a field B in my mapping, which are mutually exclusive so that each document in my index has either A or B defined. I can sort singularly on both of them, but is there a way of combining both at the same time? Something like, sort on field A if present, otherwise sort on field B.
I tried using inline script but without luck so far. Is there even a way of achieving what I would like to do?
will first sort documents by field_a ascending. By default, all documents missing field_a will be sorted to the last position (you can change that behavior if you want). Next, all ties are sorted by field_b descending, which includes the documents that were lacking field_a (because they are all tied for last). Finally, any remaining ties are sorted by their natural full-text score.
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.