I cannot search the file name from path in Elasticsearch

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

"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:

"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": "/"
						}
					}

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 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.

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

1 Like
{
	"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.

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