我想使用ElasticSearch搜索文件名(而不是文件的内容).因此,我需要找到文件名的一部分(完全匹配,没有模糊搜索).
示例:
我有以下名称的文件:
My_first_file_created_at_2012.01.13.doc
My_second_file_created_at_2012.01.13.pdf
Another file.txt
And_again_another_file.docx
foo.bar.txt
Run Code Online (Sandbox Code Playgroud)
现在我想搜索2012.01.13获取前两个文件.
搜索file或ile应返回除最后一个之外的所有文件名.
我如何使用ElasticSearch实现这一目标?
这是我测试过的,但它总是返回零结果:
curl -X DELETE localhost:9200/files
curl -X PUT localhost:9200/files -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"filename_analyzer" : {
"type" : "custom",
"tokenizer" : "lowercase",
"filter" : ["filename_stop", "filename_ngram"]
}
},
"filter" : {
"filename_stop" : {
"type" : "stop",
"stopwords" : ["doc", "pdf", "docx"]
},
"filename_ngram" : {
"type" : "nGram",
"min_gram" : …Run Code Online (Sandbox Code Playgroud)