I need to search for files and folder with in specific directories. In order to do that, elastic asks us to create the analyzer and set the tokenizer to path_hierarchy
PUT /fs
{
"settings": {
"analysis": {
"analyzer": {
"paths": {
"tokenizer": "path_hierarchy"
}
}
}
}
}
Then, create the mapping as illustrated below with two properties: name (holding the name of the file) and path (to store the directory path):
PUT /fs/_mapping/file
{
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"path": {
"type": "string",
"index": "not_analyzed",
"fields": {
"tree": {
"type": "string",
"analyzer": "paths"
}
}
}
}
}
This requires us to index the path of the directory where the file lives:
PUT /fs/file/1
{
"name": "README.txt",
"path": "/clinton/projects/elasticsearch",
}
The Question: How can i create this mapping in NEST Elastic using c#?
The analyzer is created by declaring a custom analyzer, and then setting its tokenizer to "path_tokenizer":
The second step is creating the index with required analyzer and mapping, in the code below the property "LogicalPath" will keep the locations of directories in the system"