Create visualization of top-k relevant documents

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.

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!

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.

1 Like

Did not know that was possible. It worked!

Thank you! :grinning:

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