Loading...

Kibana Short URLs

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Used:   elasticsearch 7.11.0  kibana 7.11.0 

Kibana as the GUI from Elastic for Elasticsearch provides the feature to share URLs of your objects, such as dashboard, visualisations or searches.

In the URL almost everything is scripted and you get very long URLs. This is not really convenient as sharing links via Email or Instant Messaging will clutter your message.

The solution to that is URL shortener. You could use external URL shortener like bitly or use the internal shortener. If you share a object in Kibana you can select the option Short URLs.

Kibana Shorturl

Kibana Internals

Kibana Short URLs are stored objects in the .kibana-* index.

In the Kibana DEV console or in a bash we can utilise the Elasticsearch REST API to examine, how short urls are stored.

We use the .kibana alias, which is a sytem index. This request accesses system indices: [.kibana_1], but in a future major version, direct access to system indices will be prevented by default.

We search for stored objects of type url.

GET .kibana/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "type": "url"
          }
        }
      ]
    }
  }
}

This will result in following output.

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 3.9252682,
    "hits" : [
      {
        "_index" : ".kibana_1",
        "_type" : "_doc",
        "_id" : "url:2366b6933799d1f8195cb535196b820a",
        "_score" : 3.9252682,
        "_source" : {
          "url" : {
            "url" : "/app/dashboards#/view/edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-7d,to:now))&_a=(description:%27Analyze%20mock%20web%20traffic%20log%20data%20for%20Elastic!%27s%20website%27,filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),panels:!((embeddableConfig:(enhancements:(),vis:(colors:(%27Avg.%20Bytes%27:%236ED0E0,%27Unique%20Visitors%27:%230A437C),legendOpen:!f)),gridData:(h:13,i:%272%27,w:21,x:27,y:11),id:e1d0f010-9ee7-11e7-8711-e7a007dcef99,panelIndex:%272%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:(),hiddenLayers:!(),isLayerTOCOpen:!f,mapCenter:(lat:42.16337,lon:-88.92107,zoom:3.64),openTOCDetails:!()),gridData:(h:18,i:%274%27,w:24,x:0,y:49),id:de71f4f0-1902-11e9-919b-ffe5949a18d2,panelIndex:%274%27,type:map,version:%277.11.0%27),(embeddableConfig:(enhancements:(),vis:(defaultColors:(%270%20-%2022%27:%27rgb(247,251,255)%27,%2722%20-%2044%27:%27rgb(208,225,242)%27,%2744%20-%2066%27:%27rgb(148,196,223)%27,%2766%20-%2088%27:%27rgb(74,152,201)%27,%2788%20-%20110%27:%27rgb(23,100,171)%27),legendOpen:!f)),gridData:(h:13,i:%277%27,w:24,x:0,y:36),id:%27935afa20-e0cd-11e7-9d07-1398ccfcefa3%27,panelIndex:%277%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:(),mapCenter:!(36.8092847020594,-96.94335937500001),vis:(params:(sort:(columnIndex:!n,direction:!n)))),gridData:(h:12,i:%279%27,w:21,x:27,y:24),id:%274eb6e500-e1c7-11e7-b6d5-4dc382ef7f5b%27,panelIndex:%279%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:(),vis:(colors:(%270%20-%20500%27:%23BF1B00,%271000%20-%201500%27:%237EB26D,%27500%20-%201000%27:%23F2C96D),defaultColors:(%270%20-%20500%27:%27rgb(165,0,38)%27,%271000%20-%201500%27:%27rgb(0,104,55)%27,%27500%20-%201000%27:%27rgb(255,255,190)%27),legendOpen:!f)),gridData:(h:11,i:%2711%27,w:9,x:10,y:0),id:%2769a34b00-9ee8-11e7-8711-e7a007dcef99%27,panelIndex:%2711%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:()),gridData:(h:12,i:%2713%27,w:27,x:0,y:24),id:%2742b997f0-0c26-11e8-b0ec-3bb475f6b6ff%27,panelIndex:%2713%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:()),gridData:(h:31,i:%2714%27,w:24,x:24,y:36),id:%277cbd2350-2223-11e8-b802-5bcf64c2cfb4%27,panelIndex:%2714%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:()),gridData:(h:13,i:%2715%27,w:27,x:0,y:11),id:%27314c6f60-2224-11e8-b802-5bcf64c2cfb4%27,panelIndex:%2715%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:()),gridData:(h:11,i:%2716%27,w:15,x:19,y:0),id:%2724a3e970-4257-11e8-b3aa-73fdaf54bfc9%27,panelIndex:%2716%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:(),vis:(legendOpen:!f)),gridData:(h:11,i:%2717%27,w:14,x:34,y:0),id:%2714e2e710-4258-11e8-b3aa-73fdaf54bfc9%27,panelIndex:%2717%27,type:visualization,version:%277.11.0%27),(embeddableConfig:(enhancements:()),gridData:(h:11,i:%2718%27,w:10,x:0,y:0),id:%2747f2c680-a6e3-11e8-94b4-c30c0228351b%27,panelIndex:%2718%27,type:visualization,version:%277.11.0%27)),query:(language:kuery,query:%27%27),tags:!(),timeRestore:!t,title:%27%5BLogs%5D%20Web%20Traffic%27,viewMode:view)",
            "accessCount" : 0,
            "createDate" : 1650633928160,
            "accessDate" : 1650633928160
          },
          "type" : "url",
          "references" : [ ],
          "updated_at" : "2022-04-22T13:25:28.161Z"
        }
      }
    ]
  }
}

The shorturl is in the id field. It gets translated to the stored url.

URLs in Kibana Spaces

If you use other than the default space, the namespace field is present and your id contains also the space identifier.

For instance:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.696228,
    "hits" : [
      {
        "_index" : ".kibana_1",
        "_type" : "_doc",
        "_id" : "atm:url:f691f7400a4e9a36428bb5951b25f11c",
        "_score" : 1.696228,
        "_source" : {
          "url" : {
            "url" : "/app/discover#/view/f5233590-b596-11ec-a473-fd07073bf90a?_g=(filters:!(),...)",
            "accessCount" : 6,
            "createDate" : 1649243997054,
            "accessDate" : 1649685465671
          },
          "type" : "url",
          "references" : [ ],
          "namespace" : "atm",
          "updated_at" : "2022-04-11T13:57:45.857Z"
        }
      }
    ]
  }
}

The space is atm. Pay attention to it. If you need to reorganise spaces and migrate / copy objects to spaces, shorturls will still point to its original content. It is a snapshot in time.

Search for Short URL

If you search for a specific url in a support case:

The _id field contains the namespace and the type of the saved object.

For instance a search for a dashboard in the namespace chaos looks like this.

GET .kibana/_search
{
  "query": {
    "match": {
       "_id": "chaos:dashboard:7117dbd0-82a0-11ec-8e12-2fe848755148"
    }
  }
}

For a shorturl, you can adapt.

GET .kibana/_search
{
  "query": {
    "match": {
       "_id": "atm:url:f691f7400a4e9a36428bb5951b25f11c"
    }
  }
}

Delete Shorturl

To delete saved shorturls or the documents use the Delete By Query API. You can filter for instance by the creation date.

POST /.kibana/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "type": "url"
          }
        },
        {
          "range": {
            "url.createDate": {
              "lte": "now-1d"
            }
          }
        }
      ]
    }
  }
}

Short URLs as Bookmark

I have met many user, who saved their shorturls as bookmarks. I rather recommend to avoid that, as future versions upgrades can break shorturls. If you change the dns address for your Kibana instance, the saved urls become invalid. You can use shorturls, but rather rely on a markdown page with internal links in Kibana, than collecting dozen of bookmarks. As always, save your work!

Summary

Short URLs are a good technique to share content for a snapshot of time with other co-workers. OpenSearch Dashboards v1.3.1 is a clone from Kibana and works likewise. Rather not rely on them as bookmarks, as external circumstances can render them invalid.

Please remember the terms for blog comments.