# I cannot search the file name from path in Elasticsearch

**URL:** <https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812>\
**Category:** Elasticsearch\
**Created:** [September 12, 2023, 10:46am UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812 "2023-09-12T10:46:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enes\_Can\_ISIK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enes_can_isik/32/125547_2.png) [@Enes\_Can\_ISIK](https://discuss.elastic.co/u/Enes_Can_ISIK)\
**Post date:** [September 12, 2023, 10:46am UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812/1 "2023-09-12T10:46:12Z")

</div>

I want to search filename from a path in Elasticsearch, but I cannot do it.

I have documents consisting of "name" fields with paths.  
Example:  
Name  
"folder/folder1/test/folder2/folder/"  
"folder/folder1/test/folder2/folder/test.png"

When I search for "test" here, everything under the "folder/folder1/test/" folder comes up. Likewise, when I search for "es", everything under "folder/folder1/test/" comes up. I need to be able to search in the subdirectory. For example, the expression "es" appears in "test.png".

The methods I tried are tokenizer, path hierarchy, path hierarchy reversed.

My index is like this

```auto
"name": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							},
							"tokenizer": {
								"type": "text",
								"analyzer": "my_analyzer"
							},
							"tree": {
								"type": "text",
								"analyzer": "custom_path_tree"
							},
							"tree_reversed": {
								"type": "text",
								"analyzer": "custom_path_tree_reversed"
							}
						}
					}

```

Analyzers are like this:

```auto
"analyzer": {
						"custom_path_tree_reversed": {
							"tokenizer": "custom_hierarchy_reversed"
						},
						"autocomplete": {
							"filter": [
								"lowercase",
								"autocomplete_filter"
							],
							"type": "custom",
							"tokenizer": "standard"
						},
						"custom_path_tree": {
							"tokenizer": "custom_hierarchy"
						},
						"my_analyzer": {
							"tokenizer": "my_tokenizer"
						}
					},
					"tokenizer": {
						"custom_hierarchy": {
							"type": "path_hierarchy",
							"delimiter": "/"
						},
						"my_tokenizer": {
							"type": "standard",
							"max_token_length": "30"
						},
						"custom_hierarchy_reversed": {
							"reverse": "true",
							"type": "path_hierarchy",
							"delimiter": "/"
						}
					}

```

---

<div class="post-metadata">

**Author:** ![Enes\_Can\_ISIK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enes_can_isik/32/125547_2.png) [@Enes\_Can\_ISIK](https://discuss.elastic.co/u/Enes_Can_ISIK)\
**Post date:** [September 12, 2023, 1:51pm UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812/2 "2023-09-12T13:51:38Z")

</div>

update

---

<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:** [September 12, 2023, 2:18pm UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812/3 "2023-09-12T14:18:09Z")

</div>

> [@Enes\_Can\_ISIK](#):
>
> update

I don't see any update in your post.

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

**Author:** ![Enes\_Can\_ISIK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enes_can_isik/32/125547_2.png) [@Enes\_Can\_ISIK](https://discuss.elastic.co/u/Enes_Can_ISIK)\
**Post date:** [September 13, 2023, 9:48am UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812/4 "2023-09-13T09:48:05Z")

</div>

```auto
{
	"settings": {
		"analysis": {
			"filter": {
				"my_filter": {
					"type": "pattern_capture",
					"preserve_original": false,
					"patterns": [
						"[^/]+(?=/$|$)"
					]
				}
			},
			"analyzer": {
				"my_analyzer": {
					"tokenizer": "pattern",
					"filter": [
						"my_filter",
						"lowercase",
						"unique"
					]
				}
			}
		}
	},
	"mappings": {
		"properties": {
			"key": {
				"type": "text",
				"analyzer": "my_analyzer",
				"search_analyzer":"my_analyzer"
			}
		}
	}
}

```

Thank you Mr David for your response.

By the way, I also used an analyzer with regex filtering in this way, but I think I will try pattern replacement as a last resort, I am still open to suggestions.

---

<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:** [October 11, 2023, 9:48am UTC](https://discuss.elastic.co/t/i-cannot-search-the-file-name-from-path-in-elasticsearch/342812/5 "2023-10-11T09:48:54Z")

</div>

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