Custom scoring with multiple fields in search (Java API)


(Weilie) #1

Hi,

I am trying to do sorting by more than one fields with CustomScoreQueryBuilder.script(). I looked at the document at http://www.elasticsearch.com/docs/elasticsearch/modules/scripting/ but couldn't find any example for doing that. Looks like the most common type of scripts is:
doc['field_name'].value
If I want to sort by field A first, then by field B, how do I write such a script? Is it possible at all?

Thanks!
Weilie


(Shay Banon) #2

In order to sort first by field A, and then by field B, you don't have to
use scripting, just specify those fields as the ones to sort by. In Java,
simply call SearchRequestBuilder#addSort twice, once for fieldA, and once
for fieldB.

-shay.banon

On Fri, Oct 29, 2010 at 12:52 AM, Weilie yiweilie@gmail.com wrote:

Hi,

I am trying to do sorting by more than one fields with
CustomScoreQueryBuilder.script(). I looked at the document at
http://www.elasticsearch.com/docs/elasticsearch/modules/scripting/ but
couldn't find any example for doing that. Looks like the most common type
of
scripts is:
doc['field_name'].value
If I want to sort by field A first, then by field B, how do I write such a
script? Is it possible at all?

Thanks!
Weilie

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/custom-scoring-with-multiple-fields-in-search-Java-API-tp1789576p1789576.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #3