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

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?

Have you applied any custom mappings to the index that you're querying? If not, Elasticsearch will apply a dynamic mapping, in which a field like __path will be analyzed. 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. :slight_smile: 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:

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

abdon,

Thanks! That did it.

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