奇怪的Elasticsearch搜索结果

huangapple go评论65阅读模式
英文:

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"
    }
  }
}

huangapple
  • 本文由 发表于 2023年7月24日 17:23:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753063.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定