gpt4 book ai didi

elasticsearch - ElasticSearch按完全匹配搜索电子邮件

转载 作者:行者123 更新时间:2023-12-04 06:07:28 26 4
gpt4 key购买 nike

我需要通过电子邮件搜索联系人。根据ES documentation的最佳实现方法是使用uax_url_email标记器。这是我的索引设置:

settings: {
index: {
creation_date: "1467895098804",
analysis: {
analyzer: {
email: {
type: "custom",
tokenizer: "uax_url_email"
}
}
},
number_of_shards: "5",
number_of_replicas: "1",
uuid: "wL0P6OIaQqqYpFDvIHArTw",
version: {
created: "2030399"
}
}
}

和映射:
contact: {
dynamic: "false",
properties: {
contact_status: {
type: "string"
},
created_at: {
type: "date",
format: "strict_date_optional_time||epoch_millis"
},
email: {
type: "string"
},
id: {
type: "long"
},
mailing_ids: {
type: "long"
},
subscription_status: {
type: "string"
},
type_ids: {
type: "long"
},
updated_at: {
type: "date",
format: "strict_date_optional_time||epoch_millis"
},
user_id: {
type: "long"
}
}
}

创建索引后,我插入了两个文档:
curl -X PUT 'localhost:9200/contacts/contact/1' -d '{"contact_status": "confirmed", "email": "example@gmail.com", "id": "1", "user_id": "1", "subscription_status": "on"}'


curl -X PUT 'localhost:9200/contacts/contact/2' -d '{"contact_status": "confirmed", "email": "example@yahoo.com", "id": "2", "user_id": "2", "subscription_status": "on"}'

然后,我尝试通过电子邮件以不同的方式搜索联系人:
curl -X POST 'localhost:9200/contacts/_search?pretty' -d '{"query": {"bool": {"must": [ {"match": {"_all": { "query": "example@google.com", "analyzer": "email" } } } ] } } }'

我预期会获得1个ID = 1的结果,但点击率却是空的:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}

我测试过的下一个搜索查询是:
curl -X POST 'localhost:9200/contacts/_search?pretty' -d '{"query": {"bool": {"must": [ {"match": {"_all": { "query": "example@google", "analyzer": "email" } } } ] } } }'

返回了2个结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.016878016,
"hits" : [ {
"_index" : "contacts",
"_type" : "contact",
"_id" : "2",
"_score" : 0.016878016,
"_source" : {
"contact_status" : "confirmed",
"email" : "example@yahoo.com",
"id" : "2",
"user_id" : "2",
"subscription_status" : "on"
}
}, {
"_index" : "contacts",
"_type" : "contact",
"_id" : "1",
"_score" : 0.016878016,
"_source" : {
"contact_status" : "confirmed",
"email" : "example@gmail.com",
"id" : "1",
"user_id" : "1",
"subscription_status" : "on"
}
} ]
}
}

但是据您所知,我希望在搜索结果中得到1个文档。我究竟做错了什么?

最佳答案

用它来提出您的要求👍对我有用

GET my_index/_search
{
"query": {
"match_phrase_prefix" : {
"email": "valery@gmail.com"
}
}
}

您将获得预期的结果

关于elasticsearch - ElasticSearch按完全匹配搜索电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38246436/

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