# Search date in query string query

**URL:** <https://discuss.elastic.co/t/search-date-in-query-string-query/117838>\
**Category:** Elasticsearch\
**Created:** [January 31, 2018, 2:52pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838 "2018-01-31T14:52:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hayk\_Hovhanisyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hayk_hovhanisyan/32/77342_2.png) [@Hayk\_Hovhanisyan](https://discuss.elastic.co/u/Hayk_Hovhanisyan)\
**Post date:** [January 31, 2018, 2:52pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/1 "2018-01-31T14:52:59Z")

</div>

ElasticSearch "2.4.4"  
Java "1.8.0\_151"

Hi there,

I am using query string query, and I need to have matching:

Data: `"text" : "8 Derailed 2017-07-17 user user Dermot Mac Ateer 2017-07-03 2017-07-11"`  
User Input: `2017-07-17`  
Elastic query: `{ "query":{ "query_string":{ "query":"text:2017/17/07" } } }`

Expected result: match all fields which have `2017-07-17`

Expected result: match all data and not only those who have exact `2017-07-17` inside

thanks in advance.  
regards Hayk Hovhannisyan

---

<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 31, 2018, 4:32pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/2 "2018-01-31T16:32:00Z")

</div>

It depends of the analyzer you are using.

Try the `_analyze` endpoint to understand what is happening.

---

<div class="post-metadata">

**Author:** ![kscarr73](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kscarr73/32/19670_2.png) [@kscarr73](https://discuss.elastic.co/u/kscarr73)\
**Post date:** [January 31, 2018, 4:36pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/3 "2018-01-31T16:36:57Z")

</div>

Based on this example, it appears you would need to do a regex search, which would KILL performance depending on the number of records.

The regular expression would look something like:

```
2017.07.17

```

If you could parse out the text, and add a date field, this would make searching a lot easier.

---

<div class="post-metadata">

**Author:** ![Hayk\_Hovhanisyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hayk_hovhanisyan/32/77342_2.png) [@Hayk\_Hovhanisyan](https://discuss.elastic.co/u/Hayk_Hovhanisyan)\
**Post date:** [January 31, 2018, 5:37pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/4 "2018-01-31T17:37:49Z")

</div>

Hi David,  
by default as far as I understand used **standard** analyzer.  
I also in my configurations have already implemented **bigrams** analyzer.

---

<div class="post-metadata">

**Author:** ![Hayk\_Hovhanisyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hayk_hovhanisyan/32/77342_2.png) [@Hayk\_Hovhanisyan](https://discuss.elastic.co/u/Hayk_Hovhanisyan)\
**Post date:** [January 31, 2018, 5:44pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/5 "2018-01-31T17:44:08Z")

</div>

Hi Scot,  
My `text` filed type is `String`

This works: `"query" : "text:\"2017-06-11\""`  
This not works `2017.07.17` - even if my field type is `Date`  
`"reason": "Invalid format: "2017.06.11" is malformed at ".06.11""`

My worries that this is not best solution, because for same field I need to have complicated search, in order to search:

- via free text search
- via dates
- via numbers
- via wildcards
- via partial text (with spaces)
- via all this words
- via exact matching

and so on.

Before we are using for some fields Regex search, for others Term or Match searches based on BA.

regards Hayk Hovhannisyan

---

<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 28, 2018, 5:44pm UTC](https://discuss.elastic.co/t/search-date-in-query-string-query/117838/6 "2018-02-28T17:44:13Z")

</div>

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