# Create visualization of top-k relevant documents

**URL:** <https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443>\
**Category:** Kibana\
**Created:** [May 11, 2018, 9:17am UTC](https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443 "2018-05-11T09:17:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrida](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@phrida](https://discuss.elastic.co/u/phrida)\
**Post date:** [May 11, 2018, 9:17am UTC](https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443/1 "2018-05-11T09:17:16Z")

</div>

Hi,

I would like to create a visualization in Kibana on the top-k relevant documents based on \_score. I am able to retrieve exactly what I want in Discover (See picture). However, I have tried to create something similar in a Data Table with the Top Hits aggregation, but I am not sure how to set it up properly and I am not getting the result I need.

 ![54](https://us1.discourse-cdn.com/elastic/original/3X/8/b/8b14038f25db7a31353892a5ef29ece231d118dd.png)

I have created a Query to calculate the score:

```
{
  "aggs": {
    "top_k": {
      "aggs": {
        "max_score": {
          "max": {
            "script": "_score"
          }
        },
        "top_hit": {
          "top_hits": {
            "size": 1
          }
        }
      },
      "terms": {
        "field": "message.keyword",
        "order": {
          "max_score": "desc"
        },
        "size": 10
      }
    }
  },
  "query": {
    "function_score": {
      "functions": [
        {
          "gauss": {
            "createdAt": {
              "origin": "now",
              "scale": "1h"
            }
          }
        }
      ],
      "query": {
        "bool": {
          "minimum_should_match": 1,
          "should": [
            {
              "match_phrase": {
                "message": "Trump"
              }
            },
            {
              "match_phrase": {
                "message": "America"
              }
            },
            {
              "match_phrase": {
                "message": "President"
              }
            }
          ]
        }
      }
    }
  }
}

```

Is it possible to create a visualization that gives me a list over the top-k most relevant documents based on the query?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [May 11, 2018, 7:14pm UTC](https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443/2 "2018-05-11T19:14:52Z")

</div>

If you save your search in discover is that sufficient? On the dashboard page you can click on the "Saved Searches" tab and add that to a dashboard.

---

<div class="post-metadata">

**Author:** ![phrida](https://avatars.discourse-cdn.com/v4/letter/p/e47c2d/32.png) [@phrida](https://discuss.elastic.co/u/phrida)\
**Post date:** [May 12, 2018, 1:55pm UTC](https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443/3 "2018-05-12T13:55:03Z")

</div>

Did not know that was possible. It worked!

Thank you! 😀

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 9, 2018, 1:55pm UTC](https://discuss.elastic.co/t/create-visualization-of-top-k-relevant-documents/131443/4 "2018-06-09T13:55:16Z")

</div>

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