# Term query fails to returns no result when I can see the data with a different query

**URL:** <https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730>\
**Category:** Elasticsearch\
**Created:** [June 13, 2019, 9:35pm UTC](https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730 "2019-06-13T21:35:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjokinen](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@cjokinen](https://discuss.elastic.co/u/cjokinen)\
**Post date:** [June 13, 2019, 9:35pm UTC](https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730/1 "2019-06-13T21:35:58Z")

</div>

I can not figure out why this is not working in es6.4

```
query
    {
  "version":"2017-02-28",
  "operation":"GET",
  "path":"/articlesnew1/json/_search",
  "params":{
    "body": {
      "from": 0,
      "size": 50,
      "query": {
        "term" :{
          "__path":"${context.args.path}"
        }
      }
    }
  }
}

```

my data is based on this json

```
{
  "__path":"he/taxonomy_term/access_types/721",
  "description":[],
  "entity":{
    "bundle":"access_types",
    "changed":{"timestamp":1560347903,"value":"2019-06-12T13:58:23Z"},
    "tid":721,
    "machine_name":"everyone",
    "status":1,
    "type":"taxonomy_term",
    "uri":"http://dev.pantheonsite.io/access/everyone"
  },
  "name":[{"value":"Everyone"}],
  "parent":[],
  "weight":[{"value":0}]
}

```

and I am call the query like this from aws graphql

```
query{
  getTax(path:"he/taxonomy_term/access_types/721"){
    id
    path
    name
  }
}

```

all I get back is a null...no hits on the response.

Does this have something to do with the double underscores on the term name? or is there an issue with the slashes?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [June 16, 2019, 4:47pm UTC](https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730/2 "2019-06-16T16:47:29Z")

</div>

Have you applied any custom mappings to the index that you're querying? If not, Elasticsearch will apply [a dynamic mapping,](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html) in which a field like `__path` will be [analyzed](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html). This means that by default the value of `__path` will be broken up on the slashes in that field, so you can search for the individual parts `he`, `taxonomy_term`, `access_types` and `721`.

However, if you use a `term` query, then that query string is not analyzed. Elasticsearch will try to find a document that contains a `__path` field with the exact value `he/taxonomy_term/access_types/721`, which it won't, because for your document that value was chopped up.

Luckily there is a solution here. 🙂 By default, Elasticsearch will create a second field that you can query, when you index a string field: in your case named `__path.keyword`. This value contains the exact original string, without any text analysis applied to it. If you are going with the default mappings in Elasticsearch, you will want to query that field instead:

```auto
query
    {
  "version":"2017-02-28",
  "operation":"GET",
  "path":"/articlesnew1/json/_search",
  "params":{
    "body": {
      "from": 0,
      "size": 50,
      "query": {
        "term" :{
          "__path.keyword":"${context.args.path}"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![cjokinen](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@cjokinen](https://discuss.elastic.co/u/cjokinen)\
**Post date:** [June 17, 2019, 1:54pm UTC](https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730/3 "2019-06-17T13:54:53Z")

</div>

abdon,

Thanks! That did 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:** [July 15, 2019, 1:54pm UTC](https://discuss.elastic.co/t/term-query-fails-to-returns-no-result-when-i-can-see-the-data-with-a-different-query/185730/4 "2019-07-15T13:54:57Z")

</div>

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