title: Kibana - Setting the JSON input to get the latest
body: <p>I am trying to render a bar chart in kibana using the data in elasticsearch.
  I have two documents in my elasticsearch.</p>
  
  <pre><code>Document1
  {
      "Name": "BDV301",
      "CheckName": "ADAccountPrivileges",
      "CompletedDate": "2015-12-15T16:05:35.607Z"
  }
  
  Document2
  {
      "Name": "BDV301",
      "CheckName": "ADAccountPrivileges",
      "CompletedDate": "2014-12-15T16:05:35.607Z"
  }
  </code></pre>
  
  <p>In the kibana bar chart, I always want to show the latest document(in terms of the CompletedDate field)</p>
  
  <p><a href="https://i.stack.imgur.com/IPoLX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IPoLX.png" alt="enter image description here"></a></p>
  
  <p>Can I do it using the JSON Input field?
  I tried adding the json script </p>
  
  <pre><code>{
    "filter" : {
      "match_all" : { }
    },
    "sort": [
      {
        "CompletedDate": {
          "order": "desc"
        }
      }
    ],
    "size": 1
  }
  </code></pre>
  
  <p>to get the latest document in terms of the CompletedDate, but still I get the count as 2. Strangely, I don't see my JSON input in the Elasticsearch request body in Kibana.
  This is what I see in the Elasticsearch request body.</p>
  
  <pre><code>{
    "size": 0,
    "query": {
      "filtered": {
        "query": {
          "query_string": {
            "analyze_wildcard": true,
            "query": "*"
          }
        },
        "filter": {
          "bool": {
            "must": [
              {
                "range": {
                  "CompletedDate": {
                    "gte": 1292433048436,
                    "lte": 1450199448436,
                    "format": "epoch_millis"
                  }
                }
              }
            ],
            "must_not": []
          }
        }
      }
    },
    "aggs": {
      "2": {
        "terms": {
          "field": "CheckName",
          "size": 5,
          "order": {
            "_count": "desc"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/LzLwT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LzLwT.png" alt="enter image description here"></a></p>
  
  <p>Why is my JSON input script not appearing in the Elasticsearch request body?
  Kindly help.</p>