# Terms query not working for me

**URL:** <https://discuss.elastic.co/t/terms-query-not-working-for-me/130918>\
**Category:** Elasticsearch\
**Created:** [May 8, 2018, 1:14am UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918 "2018-05-08T01:14:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fish/32/19628_2.png) [@Fish](https://discuss.elastic.co/u/Fish)\
**Post date:** [May 8, 2018, 1:14am UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/1 "2018-05-08T01:14:31Z")

</div>

I am pretty new to Easticsearch. So, if my question is stupid, I apologize.

This is my question: I want search documents that have some fields. I have provided code snippet below.

I have a field called "reference number" and I want to retrieve documents whose reference numbers are 1,2 or 3.  
When I use 'match', I get the documents for each reference number.

e.g.

GET /\_search  
{  
"query": {  
"match" : { "reference number" : 1}  
}  
}

but when I use terms query, it returns nothing. The code below returns nothing. What am I missing?

GET /\_search  
{  
"query": {  
"terms" : { "reference number" : [1,2,3]}  
}  
}

---

<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:** [May 8, 2018, 6:31am UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/2 "2018-05-08T06:31:58Z")

</div>

What does this give:

```
GET /_search
{
  "query": {
    "term" : { "reference number" : 1}
  }
}
```

---

<div class="post-metadata">

**Author:** ![Fish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fish/32/19628_2.png) [@Fish](https://discuss.elastic.co/u/Fish)\
**Post date:** [May 8, 2018, 1:38pm UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/3 "2018-05-08T13:38:55Z")

</div>

Thanks for your help. It does not return anything. I have noticed that if I use another field both 'term' and 'terms' return the required results. Could this be a problem with the field name?

---

<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:** [May 8, 2018, 2:03pm UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/4 "2018-05-08T14:03:52Z")

</div>

I don't think so. Most likely a mapping issue.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem.

---

<div class="post-metadata">

**Author:** ![Fish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fish/32/19628_2.png) [@Fish](https://discuss.elastic.co/u/Fish)\
**Post date:** [May 18, 2018, 4:27pm UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/5 "2018-05-18T16:27:07Z")

</div>

You are right. The problem was with the mappig.

---

<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 15, 2018, 4:27pm UTC](https://discuss.elastic.co/t/terms-query-not-working-for-me/130918/6 "2018-06-15T16:27:19Z")

</div>

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