# Trying to run a query on Elasticsearch 2.4

**URL:** <https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525>\
**Category:** Elasticsearch\
**Created:** [April 25, 2019, 6:52pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525 "2019-04-25T18:52:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [April 25, 2019, 6:52pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/1 "2019-04-25T18:52:14Z")

</div>

Hi,  
I'm trying to pull data from elasticsearch 2.4 with a range. I'm running the following to try to get the last 5 days worth of data:

{ "query": { "range": { "timestamp": { "gte": "now-5d", "lte": "now", "format": "epoch\_millis" } } } }'

However I get the following:  
{  
"error" : {  
"root\_cause" : [ {  
"type" : "number\_format\_exception",  
"reason" : "For input string: "now-5d""  
} ],  
"type" : "search\_phase\_execution\_exception",  
"reason" : "all shards failed",  
"phase" : "query",  
"grouped" : true,  
"failed\_shards" : [ {  
"shard" : 0,  
"index" : "ui-test-setup",  
"node" : "r8bTLlBVQba8qI-yorCFnQ",  
"reason" : {  
"type" : "number\_format\_exception",  
"reason" : "For input string: "now-5d""  
}  
} ]  
},  
"status" : 400  
}  
Just wondering what I'm missing.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2019, 7:12pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/2 "2019-04-25T19:12:40Z")

</div>

Try without `"format": "epoch_millis"`

---

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [April 25, 2019, 7:14pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/3 "2019-04-25T19:14:09Z")

</div>

Thanks for replying. When I try without it I still get

{  
"error" : {  
"root\_cause" : [ {  
"type" : "number\_format\_exception",  
"reason" : "For input string: "now-5d""  
} ],  
"type" : "search\_phase\_execution\_exception",  
"reason" : "all shards failed",  
"phase" : "query",  
"grouped" : true,  
"failed\_shards" : [ {  
"shard" : 0,  
"index" : "ui-test-setup",  
"node" : "r8bTLlBVQba8qI-yorCFnQ",  
"reason" : {  
"type" : "number\_format\_exception",  
"reason" : "For input string: "now-5d""  
}  
} ]  
},  
"status" : 400  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2019, 7:34pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/4 "2019-04-25T19:34:59Z")

</div>

What is the mapping?

---

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [April 25, 2019, 7:40pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/5 "2019-04-25T19:40:16Z")

</div>

{  
"ui-test-setup" : {  
"mappings" : {  
"uiData" : {  
"properties" : {  
"customerInfo" : {  
"properties" : {  
"contact" : {  
"type" : "string"  
},  
"email" : {  
"type" : "string"  
},  
"name" : {  
"type" : "string"  
},  
"phone" : {  
"type" : "string"  
}  
}  
},  
"docType" : {  
"type" : "string"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed"  
},

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2019, 7:54pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/8 "2019-04-25T19:54:20Z")

</div>

`timestamp` is not a `date`. So you can't apply a date range query on it.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2019, 8:34pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/10 "2019-04-25T20:34:45Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Do you have a document that matches?

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [April 25, 2019, 8:43pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/11 "2019-04-25T20:43:03Z")

</div>

I'm running this command:  
GET "[http://localhost:9200/ui-test-setup/\_search?pretty](http://localhost:9200/ui-test-setup/_search?pretty)" -d '{  
"query": {  
"range": {  
"lastStarted": {  
"gte": "now-5m",  
"lte": "now",  
"format": "strict\_date\_optional\_time||epoch\_millis"  
}  
}  
}  
}'

and I'm trying to get the following doc out of it if it exists within the last 5 days.

```
  "_index" : "ui-test-setup",
  "_type" : "uiData",
  "_id" : "Last Started-truespeed-viavi-vTA-TS-1.0.4.1.g50749f1",
  "_score" : 1.0,
  "_source" : {
    "docType" : "uiData",
    "timestamp" : 1556022336877,
    "name" : "Last Started",
    "visibility" : "private",
    "user" : "user",
    "test" : {
      "mode" : "client-to-ma",
      "modeLabel" : "Client to Test Point",
      "nameOnProbe" : "truespeed",
      "selected" : true,
      "testBrandName" : "TrueSpeed",
      "testType" : "truespeed",
      "testTypeLabel" : "TrueSpeed",
      "testTypeStandard" : "RFC 6349"
    },
    "testPoints" : [ {
      "tag" : "Test Point A",
      "selected" : true,
      "type" : "inventory",
      "id" : "a70b139e-915b-5859-857e-33c4670da218",
      "name" : "altanta-stg-vta",
      "vendor" : "viavi",
      "model" : "vTA-TS",
      "version" : "1.0.4.1.g50749f1",
      "ip" : "xx.xxx.xxx.xxx",
      "port" : "2508",
      "extension" : {
        "mac" : "00:50:56:cc:5e:14",
        "lastStarted" : "2019-04-04T01:26:24Z",
        "location" : {
          "address" : "Atlanta, GA",
          "position" : null,
          "locationAutoGenerated" : false
        },

```

I get the following return instead if I run it with or without format:

```
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2019, 9:20pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/12 "2019-04-25T21:20:41Z")

</div>

Note that

```
now-5m

```

Doesn't mean today minus 5 days.

If you need further help please provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

---

<div class="post-metadata">

**Author:** ![joshuaclark](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@joshuaclark](https://discuss.elastic.co/u/joshuaclark)\
**Post date:** [April 25, 2019, 9:22pm UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/13 "2019-04-25T21:22:01Z")

</div>

Yeah, I tried minutes as well. Thanks for helping me with this.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 26, 2019, 5:34am UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/14 "2019-04-26T05:34:23Z")

</div>

Based on the document you showed it seems like the name of the field is `testPoints.extension.lastStarted` and not just `lastStarted`. Assuming you are not using a nested mapping I would recommend trying using this field name instead while removing the format specification. As the document is from early April you probably need to use `now-30d` or so.

---

<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:** [May 24, 2019, 5:48am UTC](https://discuss.elastic.co/t/trying-to-run-a-query-on-elasticsearch-2-4/178525/15 "2019-05-24T05:48:25Z")

</div>

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