gpt4 book ai didi

elasticsearch - 通过regexp在ElasticSearch中搜索电子邮件地址

转载 作者:行者123 更新时间:2023-12-03 00:08:24 25 4
gpt4 key购买 nike

如何通过regexp在Elastic中搜索以查找电子邮件地址?

我这样尝试:

{
"query": {
"regexp": {
"data": {
"value": "[\\w\\'\\.\\_\\+\\-]+@[\\w]+[\\w\\-\\.]*\\.[\\w]+",
"flags": "ALL"
}
}
}
}

但是我什么也没得到。

https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-regexp-query.html写道simbol @表示任何符号,因此应将其转义。

因此,我尝试这样:
{
"query": {
"regexp": {
"data": {
"value": "\\@",
"flags": "ALL"
}
}
}
}

像这样:
{
"query": {
"regexp": {
"data": {
"value": "\\@",
"flags": "ALL"
}
}
}
}

但我什么也没得到。

有什么想法吗?

更新
我在Ubuntu Ubuntu 16.04.2 LTS上使用5.2版本的Elastic Search。

数据样本:
curl -XPOST 'localhost:9200/my_index/index_type/_bulk?pretty' -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"data":"some text some text some text some text admin@company.comsome text some text some text "}
{"index":{"_id":"2"}}
{"data":"some text some text hr@company.comsome text some text "}
{"index":{"_id":"3"}}
{"data":"some text some text webmaster@company.comsome text some text "}

和搜索查询:
curl -XGET 'localhost:9200/my_index/index_type/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"regexp": {
"data": {
"value": "\\@",
"flags": "ALL"
}
}
}
}
'

最佳答案

使用"[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]+"正则表达式查找电子邮件地址。然后运行以下查询找到所有电子邮件地址

GET /company/employee/_search
{
"query": {
"regexp": {
"data": {
"value": "[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]+",
"flags": "ALL"
}
}
}
}

这里company作为索引,employee作为类型,data作为字段名,然后插入以下数据以检查您的查询工作:
POST /company/employee/_bulk
{"index":{"_id":"1"}}
{"data":"admin@company.com"}
{"index":{"_id":"2"}}
{"data":"hr@company.com"}
{"index":{"_id":"3"}}
{"data":"webmaster@company.com"}
{"index":{"_id":"4"}}
{"data":"abc@company.com"}
{"index":{"_id":"5"}}
{"data":"ahmed@company.com"}
{"index":{"_id":"6"}}
{"data":"md@company.com"}
{"index":{"_id":"7"}}
{"data":"boss@company.com"}
{"index":{"_id":"8"}}
{"data":"amd@company.com"}
{"index":{"_id":"9"}}
{"data":"ad@company.com"}
{"index":{"_id":"10"}}
{"data":"ed@company.com"}
{"index":{"_id":"11"}}
{"data":"etc@company.com"}
{"index":{"_id":"12"}}
{"data":"f23f23f23f23f23 d32d23d32d d32d2 3d 23"}
{"index":{"_id":"13"}}
{"data":"d23d32 d32d23d32 etc@company.com d3d23d23"}

关于elasticsearch - 通过regexp在ElasticSearch中搜索电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072665/

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