Add field to search results

I want to set field value in search results.
Let's say for some documents field xxx is not so I need to set the value based on other fields.
I tried to use a simple script below but it only adds fields object but not a field inside _source

        "query": { ... }
        "script_fields": {
            "sample_script": {
                "script": {
                    "lang": "painless",
                    "source": "params._source.title"

Is there a way to set value for using script?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.