我正在使用ElasticSearch为电影数据库构建搜索引擎。
我需要将模糊查询与短语查询结合起来,以获得两者的好处:
我也使用默认的tokeniser和一些过滤器:asciifolding,elision,lowercase,worddelimitier和自定义词干分析器(仅用于plurials)。
这是我的疑问:
POST _search
{
"query": {
"bool":{
"should": [
{"match": {
"Title" : {
"query": "scoobydoo",
"type": "phrase",
"slop" : 50
}
}},
{"match": {
"Title" : {
"query" : "scoobydoo",
"fuzziness": "1"
}
}}
]
}
}
}
这是我的配置:
PUT /canal/
{
"settings" : {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["asciifolding", "elision", "lowercase", "worddelimiter", "my_stemmer"]
}
},
"filter": {
"elision": {
"type": "elision",
"articles": ["l", "m", "t", "qu", "n", "s", "j", "d"]
},
"worddelimiter": {
"type": "word_delimiter"
},
"my_stemmer" : {
"type" : "stemmer",
"name" : ["minimal_french", "minimal_english"]
}
}
}
},
"mappings" : {
"movies" : {
"properties" : {
"Title": {
"type" : "string",
"analyzer" : "custom_analyzer",
"search_analyzer": "custom_analyzer"
}
}
}
}
}
我不得不承认,我对如何用“应该”和两个查询进行查询并不是很有信心。所以我的问题是:我的查询是正确的,还是我可以做得更好?
非常感谢! Florent的