# Latency

**URL:** <https://discuss.elastic.co/t/latency/163800>\
**Category:** Kibana\
**Created:** [January 10, 2019, 8:11pm UTC](https://discuss.elastic.co/t/latency/163800 "2019-01-10T20:11:04Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 10, 2019, 8:11pm UTC](https://discuss.elastic.co/t/latency/163800/1 "2019-01-10T20:11:05Z")

</div>

GET mule-\*/\_search

{

"query":{

"exists": { "field": "mule.api.analytics.repliedTs" }

},

"script\_fields" : {

"totalRequestTime" : {

"script" : {

"inline": "((new SimpleDateFormat(&quot;yyyy-MM-dd'T'HH:mm:ss.S&quot;).parse(doc['mule.api.analytics.repliedTs'].value).getTime()) - (new SimpleDateFormat(&quot;yyyy-MM-dd'T'HH:mm:ss.S&quot;).parse(doc['mule.api.analytics.receivedTs'].value).getTime())) ;"

}

}

}

}

The given script is working in kibana Dev Tools however we can’t use the same script for visualization that we need to generate new field by using Kibana painless script. However while generating new fields for latency to convert the string into number/Timestamp. It doesn’t convert into number, I have also tried another way to generate latency field by importing JSON it also it did not work. Could find these issue anywhere is the resources as well.

Help would be appreciated.

Thank you,

Asha.

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [January 10, 2019, 8:20pm UTC](https://discuss.elastic.co/t/latency/163800/2 "2019-01-10T20:20:28Z")

</div>

It looks like that painless script should work for a Kibana scripted field if you convert the `&quot;` entities to `"`.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 1:50pm UTC](https://discuss.elastic.co/t/latency/163800/3 "2019-01-11T13:50:00Z")

</div>

Thank you for the reply,

GET mule-\*/\_search

{

"query":{

"exists": { "field": "mule.api.analytics.repliedTs" }

},

"script\_fields" : {

"totalRequestTime" : {

"script" : {

"inline": "((new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['mule.api.analytics.repliedTs'].value).getTime()) - (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['mule.api.analytics.receivedTs'].value).getTime())) ;"

}

}

}

}

this one also din't work, could you please help me with the same.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 4:21pm UTC](https://discuss.elastic.co/t/latency/163800/4 "2019-01-11T16:21:18Z")

</div>

Hi Bill,

Latency issue is not resolved yet, could you please help me with the same.

I’ll look forward for your reply.

Thank you,

Asha.

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [January 11, 2019, 5:50pm UTC](https://discuss.elastic.co/t/latency/163800/5 "2019-01-11T17:50:34Z")

</div>

I'm not exactly sure what you are trying to do, or what you've tried so far. I would suggest looking at this guide on how to create a scripted field in Kibana: [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) . If you add a scripted field to your index pattern you should be able to use it in a visualization.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 6:07pm UTC](https://discuss.elastic.co/t/latency/163800/6 "2019-01-11T18:07:35Z")

</div>

Bill, I was able to create the filed for Latency through painless scripts, however I am not able to get the data in the Discover field where we get the data in the tables.

![](https://us1.discourse-cdn.com/elastic/original/3X/f/9/f925a047555b08546a8eb0aab99c204a6ee9010e.png)

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 6:13pm UTC](https://discuss.elastic.co/t/latency/163800/7 "2019-01-11T18:13:19Z")

</div>

In my project repTs and RecTs are in String Type and I couldn’t convert them from string to number(data) with the below painless script.

Script:

(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['mule.api.analytics.repliedTS.keyword'].value).getTime()) - (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S").parse(doc['mule.api.analytics.receivedTS.keyword'].value).getTime())

Please help me with the same as I need to finish high prior report due Today.

I would be grateful if you could help me with the same.

Thank you in Advance.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/a/7/a7f9cbacfe77d0a9f776ea36eb768b6dcb639726.png)

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [January 11, 2019, 6:23pm UTC](https://discuss.elastic.co/t/latency/163800/8 "2019-01-11T18:23:41Z")

</div>

Did you look at the scripted field documentation referenced above? This is how you can create a field in Painless and have it be available in discover or visualizations.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 6:38pm UTC](https://discuss.elastic.co/t/latency/163800/9 "2019-01-11T18:38:59Z")

</div>

Yes, the script I created and the one which is the scripted filed documentation both are same. Now my question is why am I not able to convert the string to number or date in the Index pattern

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [January 11, 2019, 7:28pm UTC](https://discuss.elastic.co/t/latency/163800/10 "2019-01-11T19:28:23Z")

</div>

If those fields contain numbers they should be mapped as numbers in Elasticsearch. You will need to reindex to accomplish this.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 7:47pm UTC](https://discuss.elastic.co/t/latency/163800/11 "2019-01-11T19:47:13Z")

</div>

Please find the attachment as field are in numbers even then I find string in data type, what would you suggest?

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

 ![](https://us1.discourse-cdn.com/elastic/original/3X/6/2/620a7edfa0040435a484b960a6452dd2b9b96bc7.png)

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 11, 2019, 8:03pm UTC](https://discuss.elastic.co/t/latency/163800/12 "2019-01-11T20:03:20Z")

</div>

Now in this situation should Elasticsearch admin in my project reindex to accomplish this?

Please suggest me.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 13, 2019, 1:53pm UTC](https://discuss.elastic.co/t/latency/163800/13 "2019-01-13T13:53:00Z")

</div>

Is there any there way we could figure this out other then reindexing. Please let me know. Thank you

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 13, 2019, 1:54pm UTC](https://discuss.elastic.co/t/latency/163800/14 "2019-01-13T13:54:15Z")

</div>

Or else will it be possible to give me a call to discuss regarding the same this has highest priority to complete.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 14, 2019, 4:46pm UTC](https://discuss.elastic.co/t/latency/163800/15 "2019-01-14T16:46:33Z")

</div>

I was able to create latency filed with the script below: doc['mule.api.analytics.repliedTs'].value.getTime() -  
doc['mule.api.analytics.receivedTs'].value.getTime()  
However when i choose latency filed it has the warning mentioned below:  
This field is present in your elasticsearch mapping but not in any documents in the search results. You may still be able to visualize or search on it.

---

<div class="post-metadata">

**Author:** ![Asha](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Asha](https://discuss.elastic.co/u/Asha)\
**Post date:** [January 14, 2019, 4:54pm UTC](https://discuss.elastic.co/t/latency/163800/16 "2019-01-14T16:54:35Z")

</div>

I was able to create latency filed with the script below: doc['mule.api.analytics.repliedTs'].value.getTime() -  
doc['mule.api.analytics.receivedTs'].value.getTime()  
However when i This field is present in your elasticsearch mapping but not in any documents in the search results. You may still be able to visualize or search on it.

---

<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:** [February 11, 2019, 4:54pm UTC](https://discuss.elastic.co/t/latency/163800/17 "2019-02-11T16:54:36Z")

</div>

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