# Interpret Text field as Date field during search

**URL:** https://discuss.elastic.co/t/interpret-text-field-as-date-field-during-search/298385
**Category:** Elasticsearch
**Created:** [February 28, 2022, 9:00am UTC](https://discuss.elastic.co/t/interpret-text-field-as-date-field-during-search/298385 "2022-02-28T09:00:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Gokulnath\_Thangavel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gokulnath_thangavel/32/102396_2.png) [@Gokulnath\_Thangavel](https://discuss.elastic.co/u/Gokulnath_Thangavel)
#### Post date: [February 28, 2022, 9:00am UTC](https://discuss.elastic.co/t/interpret-text-field-as-date-field-during-search/298385/1 "2022-02-28T09:00:37Z")

</div>

When we initially started using Elasticsearch we missed to add mappings to one of our indices. So all the Fields are having default type of "keyword". Is there any way to perform the date range search by interpreting timestamp field as date type during search?. Mapping:

```auto
{
  "index_01_2022": {
    "mappings": {
      "properties": {
        "starttime": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "timestamp": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

```

required search query:

```auto
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "timestamp": {
            "gte": "2022-01-01T00:00:00",
            "lte": "2022-01-02T00:00:00"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![casterQ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casterq/32/93257_2.png) [@casterQ](https://discuss.elastic.co/u/casterQ)
#### Post date: [February 28, 2022, 10:01am UTC](https://discuss.elastic.co/t/interpret-text-field-as-date-field-during-search/298385/2 "2022-02-28T10:01:54Z")

</div>

yes, you can use range query with keyword type filed, such as:

```auto
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "timestamp.keyword": {
            "gte": "2022-01-01T00:00:00",
            "lte": "2022-01-02T00:00:00"
          }
        }
      }
    }
  }
}

```

but，you'd better reindex your data with the correct mapping，and not to use the default mapping

---

<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: [March 28, 2022, 10:02am UTC](https://discuss.elastic.co/t/interpret-text-field-as-date-field-during-search/298385/3 "2022-03-28T10:02:21Z")

</div>

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