0

I have this query which is hitting the below table. How can I add source field to it to return specific columns from the _source field of this index?

GET mktg_percolate_postmetrics_mib/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "end_date": {
              "gte": "now-30d",
              "lte": "now",
              "format": "epoch_millis"
            }
          }
        }
      ]
    }
  },
  "size": 0,
  "aggs": {
    "2": {
      "terms": {
        "field": "post_id",
        "size": 25,
        "order": {
          "1": "desc"
        }
      },
      "aggs": {
        "1": {
          "sum": {
            "script": "doc['facebook_likes'].value + doc['facebook_shares'].value + doc['facebook_comments'].value + doc['facebook_post_consumptions_by_type_link_clicks'].value",
            "lang": "expression"
          }
        }
      }
    }
  }
}
12
  • 1
    You need to look into source filtering Commented May 16, 2017 at 12:49
  • Thanks @Val I was looking into it before. Adding source field doesn't result in anything for me. My query fetch highest engaging post in last 30 days based on the formula in the script tag. Commented May 16, 2017 at 12:54
  • Can you show how you have used the _source field in your query? Also can you tell in which client you are running your queries? Commented May 16, 2017 at 12:55
  • Which ES version are you using?? Commented May 16, 2017 at 12:56
  • "_source": { "includes": [ "facebook_comments" ], "excludes": [ ] } Cant' everything. I added this before query as per the documentation Commented May 16, 2017 at 13:02

0

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.