# Timelion query with hypen in string

**URL:** https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301
**Category:** Kibana
**Tags:** timelion
**Created:** [September 11, 2020, 10:26am UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301 "2020-09-11T10:26:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![8wlgns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/8wlgns/32/72733_2.png) [@8wlgns](https://discuss.elastic.co/u/8wlgns)
#### Post date: [September 11, 2020, 10:26am UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301/1 "2020-09-11T10:26:52Z")

</div>

Hello?

Can I use query with hypen in string on timelion expression ?

Here is query sample.  
.es(  
index=test\*,  
timefield=@timestamp,  
q='elasticsearch.index.name:test-01\_a-\*',  
metric='avg:elasticsearch.index.total.docs.count')

I want to use query with likes q='elasticsearch.index.name:test-01\_a-\*'  
But the result is wrong. Even if I try to add escape character to dash character it's not working.

Thanks!

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [September 14, 2020, 10:41am UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301/2 "2020-09-14T10:41:14Z")

</div>

That really should work, the hyphen isn't a reserved character in the queries. If you put the same query in Discover search bar, do you get the same results or different?

---

<div class="post-metadata">

### Author: ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)
#### Post date: [September 14, 2020, 10:43am UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301/3 "2020-09-14T10:43:05Z")

</div>

Hi @8wlgns,

Usually, just wrapping the value of your search in "quotes" (as in ` q='elasticsearch.index.name:"test-01_a-*"',` just works.

But I think I need to make it clear: the `q=` parameter uses the Lucene [query syntax](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html). The way to query for the values is very tight to the type of the field you are filtering by.

In this case, I'm going to assume `elasticsearch.index.name` is `type: "text"`. The default behaviour of this type is to break the query into symbol-separated words and perform the query as if performed with the OR clause (if my assumptions are correct `elasticsearch.index.name:"test-01_a-*"` will search for `elasticsearch.index.name` contains `test` or contains `01_a`).

I would suggest you use the query `q=elasticsearch.index.name.keyword:/test-01_a-.*/` instead. The `.keyword` will use the entire value for the search. And the regexp expression will allow you to search for partial values (mind regexp and wildcard requests are expensive).

For more info about Lucene Query String, please, visit [https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-query-string-query.html#query-dsl-query-string-query](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-query-string-query.html#query-dsl-query-string-query)

NB: The behaviour might be different if your cluster/index has any non-default configurations.

---

<div class="post-metadata">

### Author: ![8wlgns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/8wlgns/32/72733_2.png) [@8wlgns](https://discuss.elastic.co/u/8wlgns)
#### Post date: [September 14, 2020, 4:19pm UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301/4 "2020-09-14T16:19:51Z")

</div>

Thanks for your very detailed reply! I'll try it.

---

<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 12, 2020, 4:19pm UTC](https://discuss.elastic.co/t/timelion-query-with-hypen-in-string/248301/5 "2020-10-12T16:19:54Z")

</div>

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