# Query Terms = NULL or \[\]

**URL:** <https://discuss.elastic.co/t/query-terms-null-or/176302>\
**Category:** Elasticsearch\
**Created:** [April 10, 2019, 11:40pm UTC](https://discuss.elastic.co/t/query-terms-null-or/176302 "2019-04-10T23:40:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EliuFlorez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eliuflorez/32/40884_2.png) [@EliuFlorez](https://discuss.elastic.co/u/EliuFlorez)\
**Post date:** [April 10, 2019, 11:40pm UTC](https://discuss.elastic.co/t/query-terms-null-or/176302/1 "2019-04-10T23:40:04Z")

</div>

Hi guys, you know I have a problem with a query in "Terms" where the query is:

```auto
GET /user/_search
{
  "query": {
    "terms" : { 
      "user" : ["user-1"]
    }
  }
}

```

something so simple but it does not return anything. I put an example of index and response.

Mapper:

```auto
PUT /user/_doc/1
{
  "user" : "user-1"
}

PUT /user/_doc/2
{
  "user" : "user-2"
}

PUT /user/_doc/3
{
  "user" : "user-3"
}

```

Query Failed:

```auto
GET /user/_search
{
  "query": {
    "terms" : { 
      "user" : ["user-1"]
    }
  }
}

```

Respose Failed:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}

```

When removing "-" from terms, the result is returned but I need it to be exact, since it will be used for location queries where it must be exact, because if only "california" is indicated, it can return results from the US and California. Mexico.

Query Success:

```auto
GET /user/_search
{
  "query": {
    "terms" : { 
      "user" : ["1"]
    }
  }
}

```

Response Success:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "user",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "user" : "user-1"
        }
      }
    ]
  }
}

```

I use Terms since you can specify several locations in the same query.

I hope you help me.

Greetings.

---

<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:** [April 11, 2019, 10:17am UTC](https://discuss.elastic.co/t/query-terms-null-or/176302/2 "2019-04-11T10:17:03Z")

</div>

It's the way analyzer are working.  
You can change the mapping. Or in your case you can run:

```auto
GET /user/_search
{
  "query": {
    "terms" : { 
      "user.keyword" : ["user-1"]
    }
  }
}

```

---

<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:** [May 9, 2019, 10:17am UTC](https://discuss.elastic.co/t/query-terms-null-or/176302/3 "2019-05-09T10:17:13Z")

</div>

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