My intention is to apply a custom analyzer to this example path, then to search for this document based on keyword "bar" using Elasticsearch "query string query":
The mapping file "test_map.txt":
{
{
"settings" : {
"analysis" : {
"char_filter" : {
"replace_slash_with_space" : {
"type" : "pattern_replace",
"pattern" : "\\\\",
"replacement" : " "
}
},
"filter" : {
"custom_path_filter" : {
"type" : "pattern_capture",
"preserve_original" : true,
"patterns" : [
"(([a-z|A-Z]+)_([a-z|A-Z]+))"
]
}
},
"analyzer" : {
"custom_path_analyzer" : {
"type" : "custom",
"char_filter" : ["replace_slash_with_space"],
"tokenizer" : "whitespace",
"filter" : ["custom_path_filter"]
}
}
}
},
"mappings" : {
"_default_" : {
"properties" : {
"Path" : {"type" : "string", "analyzer" : "custom_path_analyzer"}
}
}
}
}
The data file "test.txt":
{"index": {"_type": "pathtype", "_id": "P1", "_index": "path_index"}}
{"Path": "C:\\example\\foo_bar\\test"}
Indexing data:
curl -XPOST http://localhost:9200/path_index -d @.\test_map.txt
curl -s -XPOST http://localhost:9200/_bulk --data-binary @test.txt
Tokens generated by using the custom_path_analyzer (note that foo_bar, foo and bar are tokens):
curl.exe -XGET http://localhost:9200/path_index/_analyze?analyzer=custom_path_analyzer -d 'C:\example\foo_bar\test'
{
"tokens": [
{
"end_offset": 3,
"position": 1,
"start_offset": 0,
"token": "'c:",
"type": "word"
},
{
"end_offset": 11,
"position": 2,
"start_offset": 4,
"token": "example",
"type": "word"
},
{
"end_offset": 19,
"position": 3,
"start_offset": 12,
"token": "foo_bar",
"type": "word"
},
{
"end_offset": 19,
"position": 3,
"start_offset": 12,
"token": "foo",
"type": "word"
},
{
"end_offset": 19,
"position": 3,
"start_offset": 12,
"token": "bar",
"type": "word"
},
{
"end_offset": 25,
"position": 4,
"start_offset": 20,
"token": "test'",
"type": "word"
}
]
}
Failed Queries:
curl.exe -XGET http://localhost:9200/path_index/_search?q=bar
curl.exe -XGET http://localhost:9200/path_index/_search?q=foo
Successful Queries:
curl.exe -XGET http://localhost:9200/path_index/_search?q=Path:bar
curl.exe -XGET http://localhost:9200/path_index/_search?q=Path:foo
curl.exe -XGET http://localhost:9200/path_index/_search?q=foo_bar
Why didn't [code]curl.exe -XGET http://localhost:9200/path_index/_search?q=bar[/code] returned any hits?