# Path Hierarchy Tokenization - Exclude results below certain depth

**URL:** <https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856>\
**Category:** Elasticsearch\
**Created:** [January 18, 2019, 8:02pm UTC](https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856 "2019-01-18T20:02:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![francisb](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@francisb](https://discuss.elastic.co/u/francisb)\
**Post date:** [January 18, 2019, 8:02pm UTC](https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856/1 "2019-01-18T20:02:50Z")

</div>

Hi all,

I'm attempting to search for all items at the current path level of my search and nothing lower. I have created an index like so:

```
{
	"settings": {
		"analysis": {
			"analyzer": {
				"occupation_hierarchy_analyzer": {
					"tokenizer": "path_hierarchy"
				}
			}
		}
	},
	"mappings": {
		"category": {
			"properties": {
				"path": {
					"type": "text",
					"analyzer": "occupation_hierarchy_analyzer"
				}
			}
		}
	}
}

```

Then I'm adding a set of categories with increasing depth:

```
{"index": {"_index": "occupations", "_type": "category"}}
{"path": "/","name": "Business, finance and administration occupations"}
{"index": {"_index": "occupations", "_type": "category"}}
{"path": "/Business, finance and administration occupations","name": "Senior financial administrator"}
{"index": {"_index": "occupations", "_type": "category"}}
{"path": "/Business, finance and administration occupations/Senior financial administrator","name": "Senior finance operator"}
{"index": {"_index": "occupations", "_type": "category"}}
{"path": "/Business, finance and administration occupations/Senior financial administrator/Senior finance operator","name": "Senior bank manager"}

```

Now my query looks like so:

```
{
  "query": {
  	"bool": {
  	  	"filter": {
  			"term":{
  				"path": "/Business, finance and administration occupations"
  			}
  		}	
  	}
  }
}

```

This query returns _all_ documents within that path and it's sub-paths. What I'd like is just the documents within the given path and none from a lower depth. I've searched all around, but I have yet to see a way to do this. I read documentation here: [https://www.elastic.co/guide/en/elasticsearch/guide/master/denormalization-concurrency.html](https://www.elastic.co/guide/en/elasticsearch/guide/master/denormalization-concurrency.html), which seemed to indicate the above query would only search for documents at that depth.

Any insight is greatly appreciated!

---

<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:** [January 21, 2019, 3:46pm UTC](https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856/2 "2019-01-21T15:46:01Z")

</div>

Maybe I'm missing something, but if you only want to find documents with the exact path, then why use the path\_hierarchy tokenizer? If you create the index with `path` mapped as type `keyword` (without an analyzer) instead, you will only find documents that match the exact path.

---

<div class="post-metadata">

**Author:** ![francisb](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@francisb](https://discuss.elastic.co/u/francisb)\
**Post date:** [January 21, 2019, 4:03pm UTC](https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856/3 "2019-01-21T16:03:04Z")

</div>

Hi Abdon,

Thank you, I'm brand new to Elastic Search. I tried doing what you suggested and it works exactly the way I want now. Thanks so much for the reply!

---

<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:** [February 18, 2019, 4:03pm UTC](https://discuss.elastic.co/t/path-hierarchy-tokenization-exclude-results-below-certain-depth/164856/4 "2019-02-18T16:03:23Z")

</div>

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