ElasticSearch - 匹配(电子邮件值)returns 错误的寄存器
ElasticSearch - Match (email value) returns wrong registers
我正在使用匹配来搜索特定的电子邮件,但结果是错误的。比赛 属性 给我带来了相似的结果。如果结果存在,结果显示在第一行,但当结果不存在时,它通过相同的域给我带来结果。
这是我的查询:
{
"query": {
"match" : {
"email" : "placplac@xxx.net"
}
}
}
这封电子邮件在我的基地中不存在,但是 returning 值像 banana@xxx.net, ronyvon@xxx.net*,等等
仅当查询中的值等于时,我如何才能强制return?
提前致谢。
您需要在 "email"
字段中输入 "index":"not_analyzed"
。这样,查询的唯一条件是存储到该字段的确切值(与 standard analyzer 的情况相反,如果没有列出分析器,则默认使用)。
为了说明,我设置了一个简单的映射,其中 email
字段未分析,并添加了两个简单的文档:
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"email": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
PUT /test_index/doc/1
{"email": "placplac@xxx.net"}
PUT /test_index/doc/2
{"email": "placplac@nowhere.net"}
现在您的匹配查询将 return 仅与查询完全匹配的文档:
POST /test_index/_search
{
"query": {
"match" : {
"email" : "placplac@xxx.net"
}
}
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"email": "placplac@xxx.net"
}
}
]
}
}
这是我使用的代码:
http://sense.qbox.io/gist/12763f63f2a75bf30ff956c25097b5955074508a
PS: 你实际上可能想要的是 term query or even term filter,因为你不想对查询文本进行任何分析。所以也许是这样的:
POST /test_index/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"email": "placplac@xxx.net"
}
}
}
}
}
我正在使用匹配来搜索特定的电子邮件,但结果是错误的。比赛 属性 给我带来了相似的结果。如果结果存在,结果显示在第一行,但当结果不存在时,它通过相同的域给我带来结果。
这是我的查询:
{
"query": {
"match" : {
"email" : "placplac@xxx.net"
}
}
}
这封电子邮件在我的基地中不存在,但是 returning 值像 banana@xxx.net, ronyvon@xxx.net*,等等
仅当查询中的值等于时,我如何才能强制return?
提前致谢。
您需要在 "email"
字段中输入 "index":"not_analyzed"
。这样,查询的唯一条件是存储到该字段的确切值(与 standard analyzer 的情况相反,如果没有列出分析器,则默认使用)。
为了说明,我设置了一个简单的映射,其中 email
字段未分析,并添加了两个简单的文档:
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"email": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
PUT /test_index/doc/1
{"email": "placplac@xxx.net"}
PUT /test_index/doc/2
{"email": "placplac@nowhere.net"}
现在您的匹配查询将 return 仅与查询完全匹配的文档:
POST /test_index/_search
{
"query": {
"match" : {
"email" : "placplac@xxx.net"
}
}
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"email": "placplac@xxx.net"
}
}
]
}
}
这是我使用的代码:
http://sense.qbox.io/gist/12763f63f2a75bf30ff956c25097b5955074508a
PS: 你实际上可能想要的是 term query or even term filter,因为你不想对查询文本进行任何分析。所以也许是这样的:
POST /test_index/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"email": "placplac@xxx.net"
}
}
}
}
}