我遇到问题索引和搜索可能包含或不包含空格的单词...下面是一个示例
以下是映射的设置方式:
curl -s -XPUT 'localhost:9200/test' -d '{
"mappings": {
"properties": {
"name": {
"street": {
"type": "string",
"index_analyzer": "index_ngram",
"search_analyzer": "search_ngram"
}
}
}
},
"settings": {
"analysis": {
"filter": {
"desc_ngram": {
"type": "edgeNGram",
"min_gram": 3,
"max_gram": 20
}
},
"analyzer": {
"index_ngram": {
"type": "custom",
"tokenizer": "keyword",
"filter": [ "desc_ngram", "lowercase" ]
},
"search_ngram": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
}
}'
这就是我构建索引的方式:
curl -s -XPUT 'localhost:9200/test/name/1' -d '{ "street": "Lakeshore Dr" }'
curl -s -XPUT 'localhost:9200/test/name/2' -d '{ "street": "Sunnyshore Dr" }'
curl -s -XPUT 'localhost:9200/test/name/3' -d '{ "street": "Lake View Dr" }'
curl -s -XPUT 'localhost:9200/test/name/4' -d '{ "street": "Shore Dr" }'
以下是无法正常运行的查询示例:
curl -s -XGET 'localhost:9200/test/_search?pretty=true' -d '{
"query":{
"bool":{
"must":[
{
"match":{
"street":{
"query":"lake shore dr",
"type":"boolean"
}
}
}
]
}
}
}';
如果用户试图搜索“Lake Shore Dr”,我想只匹配文件1 /“Lakeshore Dr” 如果用户试图搜索“Lakeview Dr”,我想只匹配文档3 /“Lake View Dr”
问题是我如何设置映射(tokenizer?,edgegram vs ngrams ?, ngrams的大小?)或查询(我尝试过设置minimum_should_match和分析器等),但是我未能取得预期的效果。
谢谢大家。