Score boosting (via Java API)

You can use a boost script with parameters and implement
NativeScriptFactory.

Usage would be e.g.

QueryBuilders.customScoreQuery(QueryBuilders.matchAllQuery()).
script("mybooster").lang("native").param("friends", friends)

Then you need to specify that Java class in the elasticsearch config
file (or via API)

"index", {
      ...
},
"script" : {
    "native" : {
        "mybooster" : {
            "type": "de.jetwick.es.BoostSearchScript"
        }
    }
}

The class itself looks like

class BoostSearchScript implements NativeScriptFactory {

@Override public ExecutableScript newScript(final Map<String, Object>
params) {
// friends is of type ArrayList as it was serialized via json
even it was Set before
final Collection friends = (Collection)
params.get("friends");

return new AbstractFloatSearchScript() {

  @Override public float runAsFloat() {
    float ret =

doc().numeric("myPreCalculatedScore").getFloatValue();
// use params here somehow
return ret * friends.size();
}};
...

Peter.

On 24 Jan., 22:33, Frank LaRosa fr...@studyblue.com wrote:

Can I do something like add a script field and then specify the script
field as the sort order?

On Jan 24, 3:04 pm, Frank LaRosa fr...@studyblue.com wrote:

Hi,

Is there a way to use a boost expression in Elasticsearch, via the
Java interface? If so, what's the procedure?

For example, when using Solr, I sometimes used boost expressions such
as this:

{!boost b=sum(product(rord(docType),
10),product(recip(ms(NOW,createdOn),3.16e-11,1,1),sum(product(clicks,
0.1),likes)))}

(where docType, createdOn, clicks and likes are all the names of
fields in my documents).

Can I add an expression of this type to my SearchRequestBuilder?

Thanks.