# Syntax error in Search API with query\_string and date filter

**URL:** https://discuss.elastic.co/t/syntax-error-in-search-api-with-query-string-and-date-filter/148397
**Category:** Elasticsearch
**Created:** [September 13, 2018, 2:04am UTC](https://discuss.elastic.co/t/syntax-error-in-search-api-with-query-string-and-date-filter/148397 "2018-09-13T02:04:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shankarps](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shankarps/32/78663_2.png) [@shankarps](https://discuss.elastic.co/u/shankarps)
#### Post date: [September 13, 2018, 2:04am UTC](https://discuss.elastic.co/t/syntax-error-in-search-api-with-query-string-and-date-filter/148397/1 "2018-09-13T02:04:08Z")

</div>

I need help wiht understanding this syntax. I have gone through the docs, but since I am new to ELK, I am finding it hard to make this run.

The following API query runs and returns all records that has the exact match of the phrase "Exception occurred while loading".

```
> curl --header "Content-Type:application/json" -XPOST "http://localhost:9200/_search" -d'
> {
> "query": {
> "query_string" : {
> "query" : "\"Exception occured while loading\""
> }
> }
> }'

```

I then tried running the same query, for records that are not older than 5 months.

```
> curl --header "Content-Type:application/json" -XPOST "http://localhost:9200/_search" -d'
> {
> "query": {
> "query_string" : {
> "query" : "\"Exception occured while loading\""
> },
> "filter" : [
> { "range" : { "@timestamp" : { "gte" : "{now-5M}"}}}
> ]
> }
> }'

```

I get the following error.

> {"error":{"root\_cause":[{"type":"parsing\_exception","reason":"[query\_string] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]","line":7,"col":9}],"type":"parsing\_exception","reason":"[query\_string] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]","line":7,"col":9},"status":400}

What is the reason? Is it possible to add a date filter to the query\_string clause?

Thanks for reading.

---

<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: [October 11, 2018, 2:04am UTC](https://discuss.elastic.co/t/syntax-error-in-search-api-with-query-string-and-date-filter/148397/2 "2018-10-11T02:04:09Z")

</div>

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