# How to redirect an application to a session of a specific index on Kibana

**URL:** <https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133>\
**Category:** Kibana\
**Created:** [August 1, 2022, 3:16pm UTC](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133 "2022-08-01T15:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent92](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Vincent92](https://discuss.elastic.co/u/Vincent92)\
**Post date:** [August 1, 2022, 3:16pm UTC](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133/1 "2022-08-01T15:16:44Z")

</div>

Hello,

I am developing a **javascript** application that will complete my use of Kibana.

In my application I display a table that shows all the sessions that have been requested by the user.  
I would like to **add a button in the table for each session that would then redirect to the corresponding Kibana session**.

I first tried to build the url to which to redirect my application. So I create it like this:

```auto
const diffDays = (selectedDate: Date) => Math.ceil(Math.abs(new Date().getTime() - new Date(selectedDate).getTime()) / (1000 * 60 * 60 * 24));

const diffMonths = (selectedDate: Date) => new Date(selectedDate).getMonth() - new Date().getMonth() + 12 * (new Date(selectedDate).getFullYear() - new Date().getFullYear());

const diffYears = (selectedDate: Date) => new Date(selectedDate).getFullYear() - new Date().getFullYear();

function createKibanaUrl(timestamp: Date, idSession: string): string {
        let kibanaUrl: string = "http://HOST_NAME:5601/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-"
        const timeSlotInDays = diffDays(timestamp);
        const timeSlotInMonths = diffMonths(timestamp);
        const timeSlotInYears = diffYears(timestamp);
        if (timeSlotInDays <= 30) {
            kibanaUrl = kibanaUrl + timeSlotInDays.toString() + "d,to:now))";
        } else if ( timeSlotInDays > 30 && timeSlotInDays < 365) {
            kibanaUrl = kibanaUrl + timeSlotInMonths.toString() + "M,to:now))";
        } else if (timeSlotInDays >= 365) {
            kibanaUrl = kibanaUrl + timeSlotInYears.toString() + "y,to:now))";
        }
        kibanaUrl = kibanaUrl + "&_a=(columns:!(_source),index:" + "ab4ed2e0-fe..." + ",interval:auto,query:(language:kuery,query:'some_field:%22some_value%22%20and%20_id:%22" + encodeURIComponent(idSession) + "%22'),sort:!(!('@timestamp',desc))"

        return kibanaUrl;
    }

```

I get the following url which should work:

> http://SOME\_SERVER\_NAME:5601/app/kibana#/discover?\_g=(refreshInterval:(pause:!t,value:0),time:(from:now-12d,to:now))&\_a=(columns:!(\_source),index:661de5d...e26699,interval:auto,query:(language:kuery,query:'some\_field:%22some\_value%22%20and%20\_id:%22an\_id\_encoded%22'),sort:!(!('@timestamp',desc))

But when my application is redirected to this URL, **Kibana automatically transforms the url and returns me to a base index with the default values displayed**.

The new URL created by Kibana looks like this:

> http://SOME\_SERVER\_NAME:5601/app/kibana#/discover?\_g=(refreshInterval:(pause:!t,value:0),time:(from:now-12d,to:now))&\_a=(columns:!(\_source),index:'BASIC\_INDEX',interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc)))

What I called BASIC\_INDEX in the url above corresponds to an index that exists in my organization **but does not match the index I requested before the redirect**. And as you can see, the query section of the url is totally empty.

What explains this behavior of Kibana and is there a way to avoid it please.

Continuing my research I found [this GitHub page](https://github.com/elastic/kibana/tree/main/src/plugins/share/public/url_service/redirect) that seems to show a way to redirect one's application to the Discover app of Kibana.

So I try the following to redirect my application to the index I want, without specify any id (I just want to see if I can reach the index that I asked for):

```auto
function createKibanaUrl(): string {
        let testKibana = "http://HOST_NAME:5601/app/r?l=DISCOVER_APP_LOCATOR&v=7.6.0&p={%22indexPatternId%22:%22661de5...e26699%22}";
        return testKibana;
    }

```

But with this method, the page I am redirected to tells me that the requested application was not found:

 ![probleme_redirection_kibana](https://us1.discourse-cdn.com/elastic/original/3X/1/e/1e5cc6708a75b2e93f403a11904ac5f9bde4f21d.png)

Does anyone know how to do a redirect like this to a specific index in Kibana?

EDIT:

**Looking at the web console in Kibana just after the redirection I have the following two messages that appear:**  
1.

```auto
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-P5polb1UreUSOe5V/Pv7tc+yeZuJXiOi/3fqhGsU7BE='), or a nonce ('nonce-...') is required to enable inline execution.

```

This message is marked as appearing in: `kibana#/discover?_g=…mestamp',desc)):351`

1. 

```auto
A single error about an inline script not firing due to content security policy is expected!

```

This message is marked as appearing in: `bootstrap.js:9 `

Thanks in advance if you take the time to help me.

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [August 9, 2022, 6:21am UTC](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133/2 "2022-08-09T06:21:14Z")

</div>

Hi

Which version of Kibana are you using? Are you 100% sure you're providing the right id of the index patter / data view you want to query? If yes, could you try to wrap the index param in the generated url with `'` ... so like ...` index:'idValue'`

Thx & Best,  
Matthias

---

<div class="post-metadata">

**Author:** ![Vincent92](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Vincent92](https://discuss.elastic.co/u/Vincent92)\
**Post date:** [August 9, 2022, 8:26am UTC](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133/3 "2022-08-09T08:26:23Z")

</div>

Hello,

Sorry for the inconvenience, I just realized that I had forgotten a parenthesis at the end of my dynamically generated url. In the function createKibana() at the 12 line I just had to replace `kibanaUrl = kibanaUrl + "&_a=(columns:!(_source),index:" + "ab4ed2e0-fe..." + ",interval:auto,query:(language:kuery,query:'some_field:%22some_value%22%20and%20_id:%22" + encodeURIComponent(idSession) + "%22'),sort:!(!('@timestamp',desc))"`  
by  
`kibanaUrl = kibanaUrl + "&_a=(columns:!(_source),index:" + "ab4ed2e0-fe..." + ",interval:auto,query:(language:kuery,query:'some_field:%22some_value%22%20and%20_id:%22" + encodeURIComponent(idSession) + "%22'),sort:!(!('@timestamp',desc)))"` and everything is working normally.

---

<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:** [September 6, 2022, 8:26am UTC](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133/4 "2022-09-06T08:26:38Z")

</div>

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