Sortting based on combination of ES score and two fields

Hi,

How can I sort the result based on summation of several fields?
For my application, I want to sort the results based on ( ElasticSearch
score + field_1 + field_2 )
In fact:
Final Score = ElasticSearch score + field_1 + field_2
It seems kinda recursive, but I was wondering ES is able to do so.

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/6eac0f4f-655f-4b12-840e-162276e454fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

It seems this is what I need

"script_score" : {
"script" : "_score + doc['my_numeric_field_1'].value + doc['my_numeric_field_2'].value"
}

Am I right??

On Wednesday, July 23, 2014 9:29:22 AM UTC-5, M_20 wrote:

Hi,

How can I sort the result based on summation of several fields?
For my application, I want to sort the results based on ( Elasticsearch
score + field_1 + field_2 )
In fact:
Final Score = Elasticsearch score + field_1 + field_2
It seems kinda recursive, but I was wondering ES is able to do so.

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/7686b437-a86e-4617-a4f5-378a84bb0ce9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I wrote a code ( based on ES documentation

), but it doesn't work.
Here are the code and the error message. Any suggestion?

///// journalscorenormal --> the field's name

String script = "doc['journalscorenormal'].value";
ScriptSortBuilder sortSc = SortBuilders.scriptSort(script,"float");
SearchResponse response = client
.prepareSearch(index)
.setTypes(MyVars.index.getType())
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(
QueryBuilders.fuzzyLikeThisQuery(field)
.likeText(searchTerm)).setFrom(0)
.setSize(60)
.addSort(sortSc)
.setExplain(true).execute().actionGet();

Failed to parse source
[{"from":0,"size":60,"query":{"flt":{"fields":["sentence"],"like_text":"disease"}},"explain":true,"
sort":[{"_script":{"script":"doc['journalscorenormal'].value","type":"float"}}]}]]];
nested: ScriptException[dynamic scripting disabled]; }
at
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:233)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:179)
at
org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:523)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

On Wednesday, July 23, 2014 9:35:41 AM UTC-5, M_20 wrote:

It seems this is what I need

"script_score" : {
"script" : "_score + doc['my_numeric_field_1'].value + doc['my_numeric_field_2'].value"
}

Am I right??

On Wednesday, July 23, 2014 9:29:22 AM UTC-5, M_20 wrote:

Hi,

How can I sort the result based on summation of several fields?
For my application, I want to sort the results based on ( Elasticsearch
score + field_1 + field_2 )
In fact:
Final Score = Elasticsearch score + field_1 + field_2
It seems kinda recursive, but I was wondering ES is able to do so.

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/33a3db5a-04b6-4ae6-a60f-e015e0d17ccd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.