The elasksearch request of a simple_score_function is very slow

I am running a query that looks like this, only with many filters:

{
  "size": 30,
  "query": {
    "function_score": {
      "query": {
        "filtered": {
          "query": {
            "match_all": {}
          }
        }
      },
      "script_score": {
        "script": "( doc['num'].value <= 3 || Math.random() < 1/doc['num'].value ) ? Math.random() : 0"
      },
      "boost_mode": "replace"
    }
  }
}

      

and I see the execution time is about 10x slower than without the Script function, even when using all possible filters.

We are running Elastic version 1.0.0 and using Java API (package org.elasticsearch.client)

Is there a way to achieve a similar result with better performance? Links for "Native Java Scripts" in the Elasticsearch tutorials seem to be broken.

+3


source to share





All Articles