Kibana 中的查詢 #1 回傳結果,但查詢 #2 不回傳任何結果。我只搜索“ bob ”并得到結果,但是當搜索“ bob smith ”時,沒有結果,即使“Bob Smith”存在于索引中。有什么理由嗎?
查詢 #1:回傳結果
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:什么都不回傳……為什么(?)
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" : [ ]
}
}
uj5u.com熱心網友回復:
看起來空結果的原因是您的索引映射。如果您使用“文本”型別欄位,實際上是在倒排索引中搜索,這意味著您在標記“bob”和標記“smith”(標準分析器)中搜索,而不是在“Bob Smith”中搜索。如果你想在“Bob Smith”中作為一個token進行搜索,你需要使用“keyword”型別(如果你想使用非鍵感性搜索,可以使用小寫規范化器)
例如:
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*"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/343278.html
