# Path\_hierarchy sorting

**URL:** <https://discuss.elastic.co/t/path-hierarchy-sorting/107614>\
**Category:** Elasticsearch\
**Created:** [November 14, 2017, 7:51pm UTC](https://discuss.elastic.co/t/path-hierarchy-sorting/107614 "2017-11-14T19:51:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omar\_Verduzco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omar_verduzco/32/46183_2.png) [@Omar\_Verduzco](https://discuss.elastic.co/u/Omar_Verduzco)\
**Post date:** [November 14, 2017, 7:51pm UTC](https://discuss.elastic.co/t/path-hierarchy-sorting/107614/1 "2017-11-14T19:51:07Z")

</div>

Hi have a field that is analyzed using the `path_hierarchy` tokenizer. My problem is that, if I have a path like this:  
`parent/child1/child2`  
When I execute a search using this query:

```auto
POST my_index/_search
{
  "query": {
    "term": {
      "path": {
        "value": "parent/child1"
      }
    }
  }
}

```

I get all the documents with the form `parent/child1/<child2_name>` with the same score as the document that is an exact match of `parent/child1` (no `child2`), and I need to guarantee that the document that is an exact match is at the top of the results, but I need the `path_hierarchy` tokenizer for other search cases. What would be the best way to achieve this?

Help is really appreciated.

---

<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:** [December 12, 2017, 7:51pm UTC](https://discuss.elastic.co/t/path-hierarchy-sorting/107614/2 "2017-12-12T19:51:17Z")

</div>

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