# Date Range Query without result

**URL:** <https://discuss.elastic.co/t/date-range-query-without-result/116394>\
**Category:** Elasticsearch\
**Created:** [January 21, 2018, 5:02pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394 "2018-01-21T17:02:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![remi128](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@remi128](https://discuss.elastic.co/u/remi128)\
**Post date:** [January 21, 2018, 5:02pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/1 "2018-01-21T17:02:12Z")

</div>

Hi,  
on elastic 6.1.2 a range query by date does not give a result, hope anybody can help.

Here is the query:

```
      GET /test_index/_search 
      {
        "query" : {
          "range" : {
            "testDate" : {
              "gte" : "2012-01-01 22:13:22",
              "lt" : "now"
            }
          }
        }
      }

```

Here the mapping definition of the field testDate:

```
      "testDate": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },

```

And here an example record:

```
  {
    "_index": "test_index",
    "_type": "doc",
    "_id": "0",
    "_score": 1,
    "_source": {
      "field1": "value 0",
      "field2": "other_value 0",
      "field3": "staticValue",
      "testInteger": 0,
      "active": true,
      "testDate": "2018-01-21 17:30:29",
      "title-suggest": "value 0 other_value 0",
      "description_de_DE|SHOP": "value 0 other_value 0",
      "title_de_DE|SHOP": "value 0"
    }
  },

```

Any idea?

tia

---

<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:** [January 21, 2018, 5:36pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/2 "2018-01-21T17:36:23Z")

</div>

This works well:

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "testDate": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        }
      }
    }
  }
}
PUT test/doc/1
{
  "testDate": "2018-01-21 17:30:29"
}
GET test/_search
{
  "query": {
    "range": {
      "testDate": {
        "gte": "2012-01-01 22:13:22",
        "lt": "now"
      }
    }
  }
}

```

It gives:

```auto
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "testDate": "2018-01-21 17:30:29"
        }
      }
    ]
  }
}

```

Tested on 6.1.1. Note that elasticsearch considers at index time your date as a UTC date if you don't define any timezone. Which might be your issue...

---

<div class="post-metadata">

**Author:** ![remi128](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@remi128](https://discuss.elastic.co/u/remi128)\
**Post date:** [January 21, 2018, 6:26pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/3 "2018-01-21T18:26:45Z")

</div>

this is strange. Your example works in my system either.

So the difference to my failing example is, that there i am creating the data inside a java application by using the rest client. Inside elastic they are looking quite similar, though.

---

<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:** [January 21, 2018, 6:40pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/4 "2018-01-21T18:40:37Z")

</div>

That's often the case. Pasted code is not the exact code ran.

What gives:

```auto
GET test/_mapping

```

---

<div class="post-metadata">

**Author:** ![remi128](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@remi128](https://discuss.elastic.co/u/remi128)\
**Post date:** [January 21, 2018, 6:58pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/5 "2018-01-21T18:58:05Z")

</div>

mapping of test:

```
  {
    "test": {
      "mappings": {
        "doc": {
          "properties": {
            "testDate": {
              "type": "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            }
          }
        }
      }
    }
  }

```

mapping of test\_index, where testDate looks similar to me

```
{
  "test_index": {
    "mappings": {
      "doc": {
        "properties": {
          "active": {
            "type": "boolean"
          },
          "category_ids_de_DE|SHOP": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "dateField2": {
            "type": "long"
          },
          "description_de_DE|SHOP": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "field1": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "field2": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "field3": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "testDate": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "testInteger": {
            "type": "long"
          },
          "title-suggest": {
            "type": "completion",
            "analyzer": "simple",
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50
          },
          "title_de_DE|SHOP": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}
```

---

<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:** [January 21, 2018, 8:00pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/6 "2018-01-21T20:00:50Z")

</div>

Are you doing that in an integration test by any chance?

---

<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 18, 2018, 8:01pm UTC](https://discuss.elastic.co/t/date-range-query-without-result/116394/7 "2018-02-18T20:01:00Z")

</div>

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