0

I am trying to build a query that will return both its normal document values as well as one scripted field which I need to add some string to (enclose it in a anchor tag).

A friend told me to add _source: true but it just won't work. If I add _source: true, it only returns my regular fields. If I remove _source: true it only returns the scripted_field. If I name all my fields in _source, it will ignore the scripted_field and only return the regular ones. How can I make it so that both regular and scripted fields are displayed?

PS. I am running elastic6 on AWS and this query is being run on Redash for a report.

{
    "index": "notifications_production",

    "sort" : {"created_at" : {"order" : "desc"}},

    "query": { 
        "bool": { 
          "must": [
            { "match_all": {} }
          ],
          "filter": [ 
            { "match":  { "company_id": 5054 }},
                {
                    "range" : {
                        "created_at" : {
                            "gte" : "now-30d",
                            "lte" : "now"
                        }
                    }
                }
            ]
        }
      },


     "script_fields" : {
        "sequence2" : {
            "script" : {
                "lang": "painless",
                "source": "'<a href=#>' + params._source.file_name + '</a>'"
            }
        }
    },

    "_source": true   
}
Luis Novo
  • 574
  • 5
  • 17

0 Answers0