# Dealing with multiple date fields

**URL:** <https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795>\
**Category:** Kibana\
**Tags:** elastic-stack-monitoring, elastic-stack-security, elastic-stack-alerting\
**Created:** [October 2, 2020, 1:45pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795 "2020-10-02T13:45:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [October 2, 2020, 1:45pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/1 "2020-10-02T13:45:49Z")

</div>

Hello,

We are dealing with an index that contains multiple _date_ type fields. The structure, summarized, is below:

```auto
    ...
    "entry_date": {
      "type": "date",
      "ignore_malformed": false,
      "format": "yyyy-MM-dd HH:mm:ss"
    },
    "exit_date": {
      "type": "date",
      "ignore_malformed": false,
      "format": "yyyy-MM-dd HH:mm:ss"
    },
    ...

```

Imagine that the index stores information about shops capacity, including when a customer goes in and out of the store.

In any moment, how can we obtain how many customers does the shop have in?

Example:

**Client 1** :

- entry\_date 2020-09-20 10:40:22
- exit\_date 2020-09-20 11:22:06

**Client 2:**

- entry\_date 2020-09-20 11:00:12
- exit\_date 2020-09-20 11:15:32

At 2020-09-20 11:05:00 (for example) there were two customers inside the shop. How can I visualize that info with Kibana?

Appreciate any help.  
Thanks in advance.  
🙂

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 2, 2020, 2:00pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/2 "2020-10-02T14:00:54Z")

</div>

If you have a metric visualization that simply displays the number of documents found, in combination with a kibana KQL query for `exit_date > 11:05` and `entry_date < 11:05`?

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [October 2, 2020, 2:09pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/3 "2020-10-02T14:09:13Z")

</div>

That could work for a specific date (example 11:05).  
But, could we extend that and create a date histogram with that info every moment?

Thanks @spinscale

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 5, 2020, 8:40am UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/4 "2020-10-05T08:40:43Z")

</div>

You can also take a look at the [date\_range field type](https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html), which you can use with a `date_histogram` aggregation in Kibana. Console example:

```auto
PUT visitors
{
  "mappings": {
    "properties": {
      "visiting_time": {
        "type": "date_range"
      }
    }
  }
}

PUT visitors/_doc/client1
{
  "visiting_time" : {
    "gte" : "2020-09-20T10:40:22Z", 
    "lte" : "2020-09-20T11:22:06Z"
  }
}

PUT visitors/_doc/client2
{
  "visiting_time" : {
    "gte" : "2020-09-20T11:00:12Z", 
    "lte" : "2020-09-20T11:15:32Z"
  }
}

GET visitors/_search
{
  "size": 0,
  "aggs": {
    "by_day": {
      "date_histogram": {
        "field": "visiting_time",
        "fixed_interval": "15m"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [October 5, 2020, 10:10am UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/5 "2020-10-05T10:10:04Z")

</div>

Thanks for your help @spinscale, I think we are close to the solution .

As you show, it works perfect on Dev Console, and your aggregation returns the results I expect 🙂 Thanks!

However, when trying to visualize on Kibana I can see that kibana index pattern does not map the _visiting\_time_ neither _date_ nor _date\_range_ and it seems to be the reason why I can not make visualizations with that data.

I attach two screenshots about that:

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

However I can not perform the aggregation you suggested before. Am I misunderstanding anything?  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/f/bfe7d0ef896a001abf1b7b2b374ee1f801ac4fc2.png)

PS: I'm using 7.9.1versions.

Thanks.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 5, 2020, 10:45am UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/6 "2020-10-05T10:45:20Z")

</div>

you're right, indeed this does not seem to be supported currently. You can follow the issue at [https://github.com/elastic/kibana/issues/12751](https://github.com/elastic/kibana/issues/12751) for maybe also leave a comment - if you need Kibana support then this is not an option currently, sorry for that misdirection.

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [October 5, 2020, 10:59am UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/7 "2020-10-05T10:59:46Z")

</div>

Do you think there is another way to visualize on kibana?

I have been reading lots of discussions like [Display concurrency in data on Kibana](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/4) but that script didn't worked for me.

---

<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:** [November 2, 2020, 10:59am UTC](https://discuss.elastic.co/t/dealing-with-multiple-date-fields/250795/8 "2020-11-02T10:59:46Z")

</div>

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