Home > Back-end >  Is it possible to dynamic create the Kibana visualization from the API call?
Is it possible to dynamic create the Kibana visualization from the API call?

Time:07-05

I am very new to Kibana, and I can create the visualizations in the Kibana and add them to the dashboard. If I want to embed them to my website, I need to click on Share, Embed code, Copy iFrame code and paste it to the html. Is it possible complete the whole flow without Kibana website and do them by the API and according to the user's demand (or filter)?

For example, the simple dataset for the temperature history in the elasticsearch:

location timestamp    temperature
A        Jul.1 11:00  18
A        Jul.1 17:00  20
A        Jul.1 23:00  22
A        Jul.2 5:00   24
A        Jul.2 11:00  18
A        Jul.2 17:00  20
A        Jul.2 23:00  22
B        Jul.1 11:00  32
B        Jul.1 17:00  29
B        Jul.1 23:00  27
B        Jul.2 5:00   27
B        Jul.2 11:00  32
B        Jul.2 17:00  29
B        Jul.2 23:00  27

In our website, user could view different embeded visualization by

  1. select for location A only, and display it by bar chart (temperature history)
  2. select for location A and B both, select the time range for the past 2 months, and display it by line chart (temperature history)
  3. For advanced requirement, user can choose to display in pie chart, area chart or heat map,...,etc.

Is it possible to achieve it by the Kibana? How can I do them for the whole flow?

CodePudding user response:

It is not possible using Kibana but you can use the Elasticsearch Search API for same as Kibana also use the Search API (DSL query) for getting data from Elasticsearch.

You can follow below steps:

  1. Create an Elasticsearch DSL query based on requirement.
  2. Execute Elasticsearch query using Search API.
  3. Render the data into your custom UI. There are various libraries available for chart citation so you can use any one of them.

For your first usecase, you can use simple term query and get data from Elasticsearch for specific location.

GET /_search
{
  "query": {
    "term": {
      "location ": {
        "value": "A"
      }
    }
  }
}

For your second usecase, you can use range query for filter and then aggregation for getting value.

CodePudding user response:

You can create new visualizations without the UI by uploading saved objects. However the structure and possibilities might be limited using this approach. The iframe code usually refers a specific Kibana Endpoint / Visualization or Dashboard URL. After creating a new visualization using the Saved Objects upload you also know the ID that is necessary to put it into the iframe. Didn't test it myself but this should work.

  • Related