1

I used script_score to customize the scoring:

GET /customer/_search
{
    "query": {
        "function_score": {
            "query": {
                "match": {
                    "name": "Mark"
                }
            },
            "script_score": {
              "script": {
                "lang": "painless",
                "file": "test"
              }
            }
        }
    }
}

I set "file": "test", and put test.groovy file in config/scripts directory, but I got these error:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "[script] unknown field [file], parser not found"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "[script] unknown field [file], parser not found"
  },
  "status": 400
}

[script] unknown field [file], parser not found! Why? Should I need to install some plugins?

Elasticsearch version : 6.2.3

Plugins installed: None

JVM version : 1.8.0_181

OS version: Ubuntu Linux 4.4.0-124-generic

1 Answer 1

2

File scripts have been removed in ES 6.0, you should now use stored scripts instead.

You can easily migrate your Groovy script to Painless.

First, store your script:

POST _scripts/test
{
  "script": {
    "lang": "painless",
    "source": "Math.log(_score * 2)"
  }
}

Then use it in your query:

GET /customer/_search
{
    "query": {
        "function_score": {
            "query": {
                "match": {
                    "name": "Mark"
                }
            },
            "script_score": {
              "script": {
                "id": "test"
              }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I want to do some complicated strategy to calculate the score, can I store the script code to a file?
you can store it in a file, but ultimately you'll need to store it in ES using the _scripts endpoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.