为什么elasticsearch通配符查询return没有结果?
Why does elastic search wildcard query return no results?
Kibana 中的查询 #1 returns 结果,但是查询 #2 returns 没有结果。我只搜索“bob”并得到结果,但是在搜索“bob smith”时,没有结果,即使索引中存在“Bob Smith”。有什么原因吗?
查询 #1:returns 个结果
GET people/_search
{
"query": {
"wildcard" : {
"name" : "*bob*"
}
}
}
Results:
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 23,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "people",
"_type" : "_doc",
"_id" : "xxxxx",
"_score" : 1.0,
"_source" : {
"name" : "Bob Smith",
...
查询 #2:returns 没有.. 为什么(?)
GET people/_search
{
"query": {
"wildcard" : {
"name" : "*bob* *smith*"
}
}
}
results...nothing
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
看起来空结果的原因是您的索引映射。如果您使用“text”类型字段,您实际上是在倒排索引中搜索,意味着您在标记“bob”和标记“smith”(标准分析器)中搜索而不是在“Bob Smith”中搜索。如果你想在“Bob Smith”中作为一个标记进行搜索,你需要使用“关键字”类型(如果你想使用非关键敏感搜索,可能使用小写规范化器)
例如:
PUT test
{
"settings": {
"analysis": {
"normalizer": {
"lowercase_normalizer": {
"type": "custom",
"char_filter": [],
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "lowercase_normalizer"
}
}
}
}
PUT test/_doc/1
{
"name" : "Bob Smith"
}
GET test/_search
{
"query": {
"wildcard": {
"name": "*bob* *Smith*"
}
}
}
Kibana 中的查询 #1 returns 结果,但是查询 #2 returns 没有结果。我只搜索“bob”并得到结果,但是在搜索“bob smith”时,没有结果,即使索引中存在“Bob Smith”。有什么原因吗?
查询 #1:returns 个结果
GET people/_search
{
"query": {
"wildcard" : {
"name" : "*bob*"
}
}
}
Results:
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 23,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "people",
"_type" : "_doc",
"_id" : "xxxxx",
"_score" : 1.0,
"_source" : {
"name" : "Bob Smith",
...
查询 #2:returns 没有.. 为什么(?)
GET people/_search
{
"query": {
"wildcard" : {
"name" : "*bob* *smith*"
}
}
}
results...nothing
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
看起来空结果的原因是您的索引映射。如果您使用“text”类型字段,您实际上是在倒排索引中搜索,意味着您在标记“bob”和标记“smith”(标准分析器)中搜索而不是在“Bob Smith”中搜索。如果你想在“Bob Smith”中作为一个标记进行搜索,你需要使用“关键字”类型(如果你想使用非关键敏感搜索,可能使用小写规范化器)
例如:
PUT test
{
"settings": {
"analysis": {
"normalizer": {
"lowercase_normalizer": {
"type": "custom",
"char_filter": [],
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "lowercase_normalizer"
}
}
}
}
PUT test/_doc/1
{
"name" : "Bob Smith"
}
GET test/_search
{
"query": {
"wildcard": {
"name": "*bob* *Smith*"
}
}
}