# Query with Hyphen (-) at the beginning always returns all documents of the index

**URL:** <https://discuss.elastic.co/t/query-with-hyphen-at-the-beginning-always-returns-all-documents-of-the-index/135115>\
**Category:** Elasticsearch\
**Created:** [June 8, 2018, 8:52am UTC](https://discuss.elastic.co/t/query-with-hyphen-at-the-beginning-always-returns-all-documents-of-the-index/135115 "2018-06-08T08:52:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![khoiphan](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@khoiphan](https://discuss.elastic.co/u/khoiphan)\
**Post date:** [June 8, 2018, 8:52am UTC](https://discuss.elastic.co/t/query-with-hyphen-at-the-beginning-always-returns-all-documents-of-the-index/135115/1 "2018-06-08T08:52:44Z")

</div>

Hi all,  
I have this problem.  
I have an index (ivy\_task) with mapping and its field (barCode) like this

> PUT ivy\_task/\_mapping/ElasticTaskInfo  
> {  
> "properties" : {  
> "barCode" : {  
> "type" : "text",  
> "fielddata" : true,  
> "analyzer": "keyword"  
> }  
> }  
> }

**Please note that i have 7 documents in this index**

And when i use the query like this to search (with the hyphen at the beginning):

> POST /ivy\_task/ElasticTaskInfo/\_search/  
> {  
> "query":{"query\_string": {  
> "default\_field": "barCode",  
> "query": "-t"  
> }},  
> "size": 99  
> }

As long as i put hyphen at the beginning of the query, It always returns all 7 documents. (For example: **-t**. **-d** , **-bbbbbbbbbbbbb**. **-aaaa1111** )  
Can someone help me to explain why it returns all 7 documents ?  
Here are the barCode of all 7 documents:  
**almostThere009**  
**a-tinhte001**  
**almostThere0011**  
**almostThere0012**  
**a-almostThere0014**  
**almostThere0010**  
**a-almostThere0013**

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:** [July 6, 2018, 8:53am UTC](https://discuss.elastic.co/t/query-with-hyphen-at-the-beginning-always-returns-all-documents-of-the-index/135115/2 "2018-07-06T08:53:01Z")

</div>

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