# Query string with range

**URL:** <https://discuss.elastic.co/t/query-string-with-range/85111>\
**Category:** Elasticsearch\
**Created:** [May 9, 2017, 2:15pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111 "2017-05-09T14:15:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![X\_Calibur](https://avatars.discourse-cdn.com/v4/letter/x/b2d939/32.png) [@X\_Calibur](https://discuss.elastic.co/u/X_Calibur)\
**Post date:** [May 9, 2017, 2:15pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111/1 "2017-05-09T14:15:33Z")

</div>

I'm having difficulties getting the this one right.  
What did I miss?

{  
"query": {  
"query\_string" : {  
"analyze\_wildcard": true,  
"query" : "failed to add key to cache"  
},  
"range": {  
"@timestamp": {  
"gte": "now-900s"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![lwintergerst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lwintergerst/32/18164_2.png) [@lwintergerst](https://discuss.elastic.co/u/lwintergerst)\
**Post date:** [May 9, 2017, 2:33pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111/2 "2017-05-09T14:33:15Z")

</div>

If you want to combine multiple queries - in this case the range and the query string - you will have to wrap them in a bool query. This is how the correct query will look like:

> ```
> {
> "query": {
> "bool": {
> "must": [
> {
> "query_string": {
> "analyze_wildcard": true,
> "query": "failed to add key to cache"
> }
> },
> {
> "range": {
> "@timestamp": {
> "gte": "now-500d"
> }
> }
> }
> ]
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![X\_Calibur](https://avatars.discourse-cdn.com/v4/letter/x/b2d939/32.png) [@X\_Calibur](https://discuss.elastic.co/u/X_Calibur)\
**Post date:** [May 9, 2017, 2:44pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111/3 "2017-05-09T14:44:50Z")

</div>

This does not quite seem to cut it though.

I was looking to find the EXACT term "failed to add key to cache".

This however is looking for any of the words in it.

---

<div class="post-metadata">

**Author:** ![X\_Calibur](https://avatars.discourse-cdn.com/v4/letter/x/b2d939/32.png) [@X\_Calibur](https://discuss.elastic.co/u/X_Calibur)\
**Post date:** [May 9, 2017, 2:52pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111/4 "2017-05-09T14:52:34Z")

</div>

found it!

"failed to add key to cache"  
should be  
""failed to add key to cache""

thanks!

---

<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:** [June 6, 2017, 3:02pm UTC](https://discuss.elastic.co/t/query-string-with-range/85111/5 "2017-06-06T15:02:01Z")

</div>

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