Terms query not working for me

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]}
}
}

What does this give:

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

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?

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

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

You are right. The problem was with the mappig.

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