gpt4 book ai didi

elasticsearch - ElasticSearch-匹配(电子邮件值)返回错误的寄存器

转载 作者:行者123 更新时间:2023-12-02 23:37:44 24 4
gpt4 key购买 nike

我正在使用match搜索特定的电子邮件,但结果是错误的。 match属性为我带来相似的结果。如果结果存在,则结果显示在第一行,但是当结果不存在时,它将带给我相同域的结果。

这是我的查询:

{
"query": {
"match" : {
"email" : "placplac@xxx.net"
}
}
}

该电子邮件在我的基础中不存在,但返回的值包括banana @ xxx.net ,ronyvon @ xxx.net * 等。

仅当查询中的 等于时,才能强制返回值吗?

预先感谢。

最佳答案

您需要将"index":"not_analyzed"放在"email"字段上。这样,唯一要查询的术语是已存储到该字段的确切值(与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"}

现在,您的匹配查询将仅返回与查询完全匹配的文档:
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甚至是 term filter,因为您不希望对查询文本进行任何分析。所以也许是这样的:
POST /test_index/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"email": "placplac@xxx.net"
}
}
}
}
}

关于elasticsearch - ElasticSearch-匹配(电子邮件值)返回错误的寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28416578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com