How to configure elasticsearch to sort the scored documents on a field after score for documents is calculated?

Hi,

I want to configure the ElasticSearch so that it after calculating the
score of each document corresponding to a user query, it sorts those score
documents by some other field and then give the response. There may be a
case in which some documents have same score. I want Elasticsearch to sort
those same scoring documents on some other field. That's why needed this
functionality. Can anyone tell me how can I add this functionality to my
mapping ?

Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/cc1f83fb-c00e-4b71-8e12-5b2c096714d0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

You can sort on multiple fields for tie-breakers:

If you are first sorting on a field, and not the score, you will need to
enable track_scores:

Cheers,

Ivan

On Tue, Jan 21, 2014 at 1:30 AM, coder mukulnitkkr@gmail.com wrote:

Hi,

I want to configure the Elasticsearch so that it after calculating the
score of each document corresponding to a user query, it sorts those score
documents by some other field and then give the response. There may be a
case in which some documents have same score. I want Elasticsearch to sort
those same scoring documents on some other field. That's why needed this
functionality. Can anyone tell me how can I add this functionality to my
mapping ?

Thanks

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/cc1f83fb-c00e-4b71-8e12-5b2c096714d0%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCf3YsAYXqMR_2S3p3Naw-mKZv7iPr9sW%3D37hzHsWHMvA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Ivan,

Actually my code is in java. I have seen those links but not able to
implement it in my code. I'm using customscorequerybuilder for building my
query. How can I use this sort in my code. Is there any java api for this ?
Also, Can I do this sort in my mapping itself ?

Thanks

On Wed, Jan 22, 2014 at 3:22 AM, Ivan Brusic ivan@brusic.com wrote:

You can sort on multiple fields for tie-breakers:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If you are first sorting on a field, and not the score, you will need to
enable track_scores:
Elasticsearch Platform — Find real-time answers at scale | Elastic

Cheers,

Ivan

On Tue, Jan 21, 2014 at 1:30 AM, coder mukulnitkkr@gmail.com wrote:

Hi,

I want to configure the Elasticsearch so that it after calculating the
score of each document corresponding to a user query, it sorts those score
documents by some other field and then give the response. There may be a
case in which some documents have same score. I want Elasticsearch to sort
those same scoring documents on some other field. That's why needed this
functionality. Can anyone tell me how can I add this functionality to my
mapping ?

Thanks

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/cc1f83fb-c00e-4b71-8e12-5b2c096714d0%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCf3YsAYXqMR_2S3p3Naw-mKZv7iPr9sW%3D37hzHsWHMvA%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAAVTvp44q9tj_mvgbVqVUcXnY7QQZg9jSFj85ZsYf%3D-ME%3DGgjw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

1 Like

Some pseudo-ish code using the Java API:

SearchRequestBuilder builder = ...

SortBuilder sortBuidler = org.elasticsearch.search.sort.fieldSort(field);
builder.setTrackScores(true);
builder.addSort(sortBuidler);
builder.addSort(scoreSort().order(SortOrder.DESC));

Hope this helps,

Ivan

On Tue, Jan 21, 2014 at 10:47 PM, Mukul Gupta mukulnitkkr@gmail.com wrote:

Hi Ivan,

Actually my code is in java. I have seen those links but not able to
implement it in my code. I'm using customscorequerybuilder for building my
query. How can I use this sort in my code. Is there any java api for this ?
Also, Can I do this sort in my mapping itself ?

Thanks

On Wed, Jan 22, 2014 at 3:22 AM, Ivan Brusic ivan@brusic.com wrote:

You can sort on multiple fields for tie-breakers:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If you are first sorting on a field, and not the score, you will need to
enable track_scores:
Elasticsearch Platform — Find real-time answers at scale | Elastic

Cheers,

Ivan

On Tue, Jan 21, 2014 at 1:30 AM, coder mukulnitkkr@gmail.com wrote:

Hi,

I want to configure the Elasticsearch so that it after calculating the
score of each document corresponding to a user query, it sorts those score
documents by some other field and then give the response. There may be a
case in which some documents have same score. I want Elasticsearch to sort
those same scoring documents on some other field. That's why needed this
functionality. Can anyone tell me how can I add this functionality to my
mapping ?

Thanks

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/cc1f83fb-c00e-4b71-8e12-5b2c096714d0%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCf3YsAYXqMR_2S3p3Naw-mKZv7iPr9sW%3D37hzHsWHMvA%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAAVTvp44q9tj_mvgbVqVUcXnY7QQZg9jSFj85ZsYf%3D-ME%3DGgjw%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDrh%3D3Spe1ucfLzrK%2B9QQ6brhQ4_M2gYVdGaa-ZnjkhYw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Ivan,

I tried doing the above thing in my code but it seems there is no
scoreSort() method. Are you the last sorting needs to be done this way :
addSort(scoreSort().
order(SortOrder.DESC));

Thanks

On Thu, Jan 23, 2014 at 12:51 AM, Ivan Brusic ivan@brusic.com wrote:

Some pseudo-ish code using the Java API:

SearchRequestBuilder builder = ...

SortBuilder sortBuidler = org.elasticsearch.search.sort.fieldSort(field);
builder.setTrackScores(true);
builder.addSort(sortBuidler);
builder.addSort(scoreSort().order(SortOrder.DESC));

Hope this helps,

Ivan

On Tue, Jan 21, 2014 at 10:47 PM, Mukul Gupta mukulnitkkr@gmail.comwrote:

Hi Ivan,

Actually my code is in java. I have seen those links but not able to
implement it in my code. I'm using customscorequerybuilder for building my
query. How can I use this sort in my code. Is there any java api for this ?
Also, Can I do this sort in my mapping itself ?

Thanks

On Wed, Jan 22, 2014 at 3:22 AM, Ivan Brusic ivan@brusic.com wrote:

You can sort on multiple fields for tie-breakers:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If you are first sorting on a field, and not the score, you will need to
enable track_scores:
Elasticsearch Platform — Find real-time answers at scale | Elastic

Cheers,

Ivan

On Tue, Jan 21, 2014 at 1:30 AM, coder mukulnitkkr@gmail.com wrote:

Hi,

I want to configure the Elasticsearch so that it after calculating the
score of each document corresponding to a user query, it sorts those score
documents by some other field and then give the response. There may be a
case in which some documents have same score. I want Elasticsearch to sort
those same scoring documents on some other field. That's why needed this
functionality. Can anyone tell me how can I add this functionality to my
mapping ?

Thanks

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/cc1f83fb-c00e-4b71-8e12-5b2c096714d0%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCf3YsAYXqMR_2S3p3Naw-mKZv7iPr9sW%3D37hzHsWHMvA%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAAVTvp44q9tj_mvgbVqVUcXnY7QQZg9jSFj85ZsYf%3D-ME%3DGgjw%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDrh%3D3Spe1ucfLzrK%2B9QQ6brhQ4_M2gYVdGaa-ZnjkhYw%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAAVTvp5GM3r_LhSVMSYrj%2Bch20vcCp5k%3DMxW9wjHk1-8ryH94w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.