2

The index has the capability of taking custom scripting in Python, but I can't find an example of custom scripting written in Python anywhere. Does anybody have an example of a working script? One with something as simple as an if-statement would be amazing.

2 Answers 2

2

A simple custom scoring query using python (assuming you have the plugin installed).

{
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "script_score": {
        "lang": "python",
        "script": [
          "if _score:",
          "  _score"
        ]
      },
      "boost_mode": "replace"
    }
  },
  "track_scores": true
}
Sign up to request clarification or add additional context in comments.

1 Comment

Just the custom scoring plugin for the python language @chimpsarehungry : github.com/elasticsearch/elasticsearch-lang-python
0

Quoted from elasticsearch ML -

Luca pointed out that ES calls python with an 'eval'

PyObject ret = interp.eval((PyCode) compiledScript);

Just make sure your code pass through the eval.

Comments

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.