我正在使用 Elasticsearch v 7.3.1 并尝试实现部分搜索。所有搜索都很顺利,但是当我查询“ John Oxford ”时,“John”与文档匹配,但整个文档中没有“ Oxford ”。但仍然向我显示文档而不是显示空结果。
我该怎么做才能在我们查询John Oxford时不返回文档?
我的映射、设置、示例文档和学生数据查询如下。
映射
PUT student
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}, "mappings" : {
"properties" : {
"DOB" : {
"type" : "text"
},
"email" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"first_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"home_phone" : {
"type" : "text"
},
"last_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"student_id" : {
"type" : "text"
}
}
}
}
样本文件
POST student/_doc
{
"DOB": "1983-12-04",
"email": "johndoe@gmail.fr",
"first_name": "john",
"home_phone": 1242432,
"last_name": "doe",
"student_id": 28
}
询问
GET student/_search
{
"query": {
"multi_match": {
"query": "john oxford",
"type": "bool_prefix",
"analyzer": "standard",
"fields": [
"first_name",
"last_name",
"email",
"DOB",
"home_phone",
"student_id"
]
}
}
}
以下是我想要的结果
- 1242 - 部分匹配 home_phone
- joh do - 部分匹配“John”和“Doe”
- 1983-12-04 - 匹配 DOB
- johndoe - 电子邮件部分匹配
- doe - 匹配姓氏