英文:
Strange search result with Elasticsearch
问题
我有这个短语存储在地址字段下:“Koželužská 290, 33805 Mýto”
我试图像这样搜索这个字符串的一部分:
{
“query”:{
“query_string”:{
“query”:“Koželužská 290, 33*”,
“fields”:[“address”],
“default_operator”:“AND”
}
}
}
我得到了一个正确的记录结果。
但是如果我尝试像这样搜索字符串的一部分:
{
“query”:{
“query_string”:{
“query”:“Koželužská 290,*”,
“fields”:[“address”],
“default_operator”:“AND”
}
}
}
我没有得到任何结果。
有人知道为什么或者出了什么问题吗?
英文:
I have this phrase stored under the field address: "Koželužská 290, 33805 Mýto"
I'm trying to search for part of this string like this:
{
"query": {
"query_string": {
"query": "Koželužská 290, 33*",
"fields": ["address"],
"default_operator": "AND"
}
}
}
I get the result of one record which is correct.
But if I try to search for part of the string like this:
{
"query": {
"query_string": {
"query": "Koželužská 290,*",
"fields": ["address"],
"default_operator": "AND"
}
}
}
I don't get any result.
Does anyone know why or what is wrong?
答案1
得分: 1
使用配置: "analyze_wildcard": true,
通过将analyze_wildcard设置为true,以*结尾的查询将被分析,并将根据不同的标记构建布尔查询,确保在前N-1个标记上精确匹配,并在最后一个标记上进行前缀匹配。
{
"profile": false,
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "Koželužská 290,*",
"fields": [
"address"
],
"default_operator": "AND"
}
}
}
英文:
Use the config: "analyze_wildcard": true,
> By setting analyze_wildcard to true, queries that end with a * will be
> analyzed and a boolean query will be built out of the different
> tokens, by ensuring exact matches on the first N-1 tokens, and prefix
> match on the last token.
{
"profile": false,
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "Koželužská 290,*",
"fields": [
"address"
],
"default_operator": "AND"
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论