This plugin provides a feature to change top N documents in a search result.
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Elasticsearch DynaRank Plugin


DynaRank Plugin provides a feature for Dynamic Ranking at a search time. You can change top N documents in the search result with your re-ordering algorithm. Elasticsearch has rescoring, but DynaRank is different as below:

  • DynaRank's reranking is executed on requested node only, not on each shard.
  • DynaRank uses a script language for reranking.


Versions in Maven Repository


Please file an issue. (Japanese forum is here.)


For 5.x

$ $ES_HOME/bin/elasticsearch-plugin install org.codelibs:elasticsearch-dynarank:5.5.1

For 2.x

$ $ES_HOME/bin/plugin install org.codelibs/elasticsearch-dynarank/2.4.0

Getting Started

Create Sample Data

Create "sample" index:

$ COUNT=1;while [ $COUNT -le 100 ] ; do curl -XPOST 'localhost:9200/sample/data' -d "{\"message\":\"Hello $COUNT\",\"counter\":$COUNT}";COUNT=`expr $COUNT + 1`; done

100 documents are inserted. You can see 10 documents by an ascending order of "counter" field:

$ curl -XPOST "" -d'
   "query": {
      "match_all": {}
   "fields": [
   "sort": [
         "counter": {
             "order": "asc"

Enable Reranking

DynaRank plugin is enabled if your re-order script is set to the target index:

$ curl -XPUT 'localhost:9200/sample/_settings?'
$ curl -XPUT 'localhost:9200/sample/_settings?index.dynarank.reorder_size=5'

The above script is:

searchHits.sort {s1, s2 -> s2.getSource().get('counter').value() - s1.getSource().get('counter').value()} as[]

This setting sorts top 5 documents (5 is given by reorder_size) by a descending order of "counter" field, and others are by an ascending order.

Disable Reranking

Set an empty value to index.dynarank.script_sort.script:

$ curl -XPUT 'localhost:9200/sample/_settings?index.dynarank.script_sort.script='


dynarank_diversity_sort Script Sort

DynaRank plugin provides a sort feature for a diversity problem. The sort script is dynarank_diversity_sort. The configuration is below:

curl -XPUT 'localhost:9200/sample/_settings' -d '
  "index" : {
          "diversity_fields":["filedname1", "filedname2"],
          "diversity_thresholds":[0.95, 1]

diversity_fields is fields for a diversity. diversity_thresholds is a threshold for a similarity of each document.