我试图在Elasticsearch中实现简单的多令牌同义词,但没有得到我期望的结果。这里有一些卷曲:
curl -XPOST "http://localhost:9200/test" -d'
{
"mappings": {
"my_type": {
"properties": {
"blah": {
"type": "string",
"analyzer": "my_synonyms"
}
}
}
},
"settings": {
"index": {
"analysis": {
"filter": {
"my_syn_filt": {
"type": "synonym",
"synonyms": [
"foo bar, fooo bar"
]
}
},
"analyzer": {
"my_synonyms": {
"filter": [
"lowercase",
"my_syn_filt"
],
"tokenizer": "keyword"
}
}
}
}
}
}'
为一些文档编制索引:
curl -XPUT localhost:9200/test/my_type/1 -d '{"blah": "fooo bar"}'
curl -XPUT localhost:9200/test/my_type/2 -d '{"blah": "fooo barr"}'
curl -XPUT localhost:9200/test/my_type/3 -d '{"blah": "foo bar"}'
现在查询:
curl -XPOST "http://localhost:9200/test/_search" -d'
{
"query": {
"match": {
"blah": "foo bar"
}
}
}'
我希望能拿回文件1和3,但只能拿回3。有人知道问题可能是什么吗?
进一步检查后,当直接调用分析器时,我也没有得到预期的令牌:
curl 'localhost:9200/test/_analyze?analyzer=my_synonyms' -d 'fooo bar'
当我需要两个标记:“fooo-bar”和“foo-bar”时,只返回一个标记“fooo-bar”。