This plugin provides a feature to change top N documents in a search result.
Latest commit 9d06632 Oct 4, 2016 @marevol marevol committed on GitHub Update
Failed to load latest commit information.
src add ignored objects Oct 3, 2016
.gitignore initial commit. Aug 26, 2014
LICENSE Initial commit Aug 26, 2014 Update Oct 4, 2016
pom.xml [maven-release-plugin] prepare for next development iteration Sep 25, 2016

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.


Version Elasticsearch
master 2.4.X
2.4.0 2.4.0
2.3.1 2.3.5
2.2.0 2.2.0
2.1.0 2.1.1
1.6.0 1.6.0
1.5.1 1.5.2
1.4.5 1.4.2
1.3.0 1.3.2


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


Install DynaRank Plugin

$ $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.field('counter').value() - s1.field('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.