【发布时间】:2020-07-29 09:32:07
【问题描述】:
我正在使用 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 - 匹配出生日期
- johndoe - 电子邮件部分匹配
- doe - 匹配姓氏
【问题讨论】:
-
抱歉,无法理解您的意思...如果您想进行部分搜索,“john”一词可能是“john oxford”的部分结果。您是否要搜索“john oxford”这一表达是否包含在您的文档中?或者您将检索所有同时包含 john 和 oxford 的文档?
-
@Lupanoide 请检查更新的问题。我已经更新了要求。我的要求应该可以满足。
-
@Lupanoide 请帮助我实现我的目标。谢谢
标签: elasticsearch elastic-stack elasticsearch-query elasticsearch-7