Trying to return _source and script_fields

[Solved] [2.4.3] Here's my query. It's only returning the script_field, new_sales, and forgets about returning the source. What can I do to return my _source document as well as the calculated field.

Thanks!

   GET weekly_sales/_search
    {
      "query": {
        "match_all": {}
      },
      "script_fields": {
        "new_sales": {
          "script": "doc['total_sale_amount'].value * 2"
        }
      }
    }

#example return:
"hits": [
{
"_index": "weekly_sales",
"_type": "weekly_sales",
"_id": "304-02-0689-2016-12-17-3004",
"_score": 1,
"fields": {
"new_sales": [
-16.62
]
}
}]

1 Like

Hi @JonathanAaron,

this should do the trick:

GET weekly_sales/_search
{
   "query": {
      "match_all": {}
   },
   "_source": true,
   "script_fields": {
      "new_sales": {
         "script": "doc['total_sale_amount'].value * 2"
      }
   }
}

Daniel

5 Likes

That was what I was looking for! Thanks!

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