# KQL Query or Elastic query to fetch data for current month

**URL:** https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045
**Category:** Kibana
**Created:** [April 28, 2023, 10:23am UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045 "2023-04-28T10:23:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)
#### Post date: [April 28, 2023, 10:23am UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/1 "2023-04-28T10:23:14Z")

</div>

Hi all,

I'm trying to fetch data only for current month of april 2023.

For example,

I have a query filter condition in my search bar in my kibana data table as

`configuredDate > now-30d`

which gives me data for past 1 month.

But I want to fetch data from April 1st to April 28th 2023.  
The above query fetches me data from March 30th 2023 to April 28th 2023.

I want to fetch data from 1st of the current month to current date for other queries.  
This data may dynamic , but i want to fetch from 1st of current month i.e from April 1st 2023 to April 28th 2023 or current timestamp.

I cannot use timepicker for this.

 ![Screenshot 2023-04-28 at 3.04.57 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/9/59ff28ec660aa8e02f2460158408219bdc2aebb6.png)

Any way to go about it?

Regards

---

<div class="post-metadata">

### Author: ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)
#### Post date: [May 3, 2023, 2:39pm UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/2 "2023-05-03T14:39:53Z")

</div>

See if `now/M` gets you what you want. That should round it down to the nearest month.

---

<div class="post-metadata">

### Author: ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)
#### Post date: [May 4, 2023, 5:21am UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/3 "2023-05-04T05:21:58Z")

</div>

No, the below throws an error.

`configuredDate > now/M`

Any other way I can show present month

---

<div class="post-metadata">

### Author: ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)
#### Post date: [May 4, 2023, 1:03pm UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/4 "2023-05-04T13:03:08Z")

</div>

So instead of using KQL, could you put the time relevant part in the query DSL. Here's the query I'm using:

```auto
GET example/_search
{
  "query": {
    "range": {
      "@timestamp": {
        "gt": "now/M"
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Sandeep\_Raju](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sandeep\_Raju](https://discuss.elastic.co/u/Sandeep_Raju)
#### Post date: [May 5, 2023, 11:12am UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/5 "2023-05-05T11:12:35Z")

</div>

@Wave Thank you!

I tried in DSL query and it worked as below:

```auto
{
  "query": {
    "range": {
      "configuredDate": {
        "gte": "now/M"
      }
    }
  }
}

```

I just had to change from **gt** to **gte** & it worked!

---

<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: [June 2, 2023, 11:12am UTC](https://discuss.elastic.co/t/kql-query-or-elastic-query-to-fetch-data-for-current-month/331045/6 "2023-06-02T11:12:57Z")

</div>

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