好吧,我找到了一种更简单的方法...关键是我只需要能够通过三种可能的组合进行搜索...实际上不需要直接引用 grp typ 或 num。
Path_analyer 正在做我想做的事:
# Create a new index with custom path_hierarchy analyzer
# See http://www.elasticsearch.org/guide/reference/index-modules/analysis/pathhierarchy-tokenizer.html
curl -XPUT "localhost:9200/accts-test" -d '{
"settings": {
"analysis": {
"analyzer": {
"accts-analyzer": {
"type": "custom",
"tokenizer": "accts-tokenizer"
}
},
"tokenizer": {
"accts-tokenizer": {
"type": "path_hierarchy",
"delimiter": "-",
"reverse": "true"
}
}
}
},
"mappings": {
"_default_": {
"_timestamp" : {
"enabled" : true,
"store" : true
}
},
"doc": {
"properties": {
"name": { "type": "string"},
"accts": {
"type": "string",
"index_name": "acct",
"index_analyzer": "accts-analyzer",
"search_analyzer": "keyword"
}
}
}
}
}'
然后通过 _analyzer 端点对其进行测试显示:
# curious about path analyzer? test it:
echo testing analyzier
curl -XGET 'localhost:9200/accts-test/_analyze?analyzer=accts-analyzer&pretty=1' -d '111-BBB-2233445566'
echo
{
"tokens" : [ {
"token" : "111-BBB-2233445566",
"start_offset" : 0,
"end_offset" : 18,
"type" : "word",
"position" : 1
}, {
"token" : "BBB-2233445566",
"start_offset" : 4,
"end_offset" : 18,
"type" : "word",
"position" : 1
}, {
"token" : "2233445566",
"start_offset" : 8,
"end_offset" : 18,
"type" : "word",
"position" : 1
} ]
}