【发布时间】:2017-07-20 19:09:47
【问题描述】:
我正在尝试重建我的弹性搜索查询,因为我发现我没有收到我正在寻找的所有文档。
所以,假设我有这样的文档:
{
"id": 1234,
"mail_id": 5,
"sender": "john smith",
"email": "johnsmith@gmail.com",
"subject": "somesubject",
"txt": "abcdefgh\r\n",
"html": "<div dir=\"ltr\">abcdefgh</div>\r\n",
"date": "2017-07-020 10:00:00"
}
我有几百万这样的文档,现在我正试图通过这样的查询来搜索一些:
{
"sort": [
{
"date": {
"order": "desc"
}
}
],
"query": {
"bool": {
"minimum_should_match": "100%",
"should": [
{
"multi_match": {
"type": "cross_fields",
"query": "abcdefgh johnsmith john smith",
"operator": "and",
"fields": [
"email.full",
"sender",
"subject",
"txt",
"html"
]
}
}
],
"must": [
{
"ids": {
"values": [
"1234"
]
}
},
{
"term": {
"mail_id": 5
}
}
]
}
}
}
对于这样的查询,一切都很好,但是当我想通过查询“gmail”或“com”来查找文档时,它就不起作用了。
"query": "abcdefgh johnsmith john smith gmail"
"query": "abcdefgh johnsmith john smith com"
只有当我搜索“gmail.com”时它才会起作用 “查询”:“abcdefgh johnsmith john smith gmail.com”
所以...我试图附加分析器
...
"type": "cross_fields",
"query": "abcdefgh johnsmith john smith",
"operator": "and",
"analyzer": "simple",
...
根本没有帮助。我能够找到此文档的唯一方法是定义正则表达式,例如:
"minimum_should_match": 1,
"should": [
{
"multi_match": {
"type": "cross_fields",
"query": "fdsfs wukamil kam wuj gmail.com",
"operator": "and",
"fields": [
"email.full",
"sender",
"subject",
"txt",
"html"
]
}
},
{
"regexp": {
"email.full": ".*gmail.*"
}
}
],
但在这种方法中,我必须将(查询 * 字段)正则表达式对象添加到我的 json 中,所以我认为这不是最好的解决方案。我也知道通配符,但它会像正则表达式一样混乱。
如果有人遇到这样的问题并知道解决方案,我将非常感谢您的帮助:)
【问题讨论】:
-
你能显示你的
email字段映射在ES内部吗? -
email.full 只是 {"type" : "text"}
标签: elasticsearch