使用 ElasticSearch 索引电子邮件 - 映射问题
Index email with ElasticSearch - mapping problem
我使用 ES v7。我想使用 ElasticSearch 索引电子邮件地址,但使用 uax_url_email 分词器。
我想用完整的电子邮件地址搜索 Elastic。
我试过使用这个映射:
PUT /test
{
"settings": {
"analysis": {
"filter": {
"email": {
"type": "pattern_capture",
"preserve_original": 1,
"patterns": [
"([^@]+)",
"(\p{L}+)",
"(\d+)",
"@(.+)",
"([^-@]+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email"
}
}
}
}
}
但出现错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
}
],
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
},
"status": 400
}
有什么问题吗?此映射应该如何显示?
您的请求格式错误,您正在将 1
传递给 preserve_original
参数,该参数只接受异常中提到的 true
和 false
。
除此之外,还有一些问题,例如您使用的 String
数据类型在 v7.1 中已弃用,并且 emails
在 properties
之前出现 JSON.
在我的本地测试正确的映射
{
"settings": {
"analysis": {
"filter": {
"email": {
"type": "pattern_capture",
"preserve_original": true,
"patterns": [
"([^@]+)",
"(\p{L}+)",
"(\d+)",
"@(.+)",
"([^-@]+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"properties": {
"email": {
"type": "text",
"analyzer": "email"
}
}
}
}
谢谢。
我插入了几封电子邮件以使用这个更正后的映射建立索引。
现在,当我搜索特定电子邮件时,我会得到所有结果。
我只想有一个记录。我该怎么做?
http://localhost:9200/test/_search?q=email:abc@abc.net
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 0.21149008,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "0IWQlXcBnPuV0JvQXCHW",
"_score": 0.21149008,
"_source": {
"email": "abc@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "0oWUlXcBnPuV0JvQISFe",
"_score": 0.21149008,
"_source": {
"email": "abc1@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "z4WQlXcBnPuV0JvQNCGn",
"_score": 0.19982167,
"_source": {
"email": "abc2@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "0YWQlXcBnPuV0JvQdiHo",
"_score": 0.19982167,
"_source": {
"email": "abc3@abc.net"
}
}
]
}
}
我使用 ES v7。我想使用 ElasticSearch 索引电子邮件地址,但使用 uax_url_email 分词器。 我想用完整的电子邮件地址搜索 Elastic。
我试过使用这个映射:
PUT /test
{
"settings": {
"analysis": {
"filter": {
"email": {
"type": "pattern_capture",
"preserve_original": 1,
"patterns": [
"([^@]+)",
"(\p{L}+)",
"(\d+)",
"@(.+)",
"([^-@]+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email"
}
}
}
}
}
但出现错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
}
],
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
},
"status": 400
}
有什么问题吗?此映射应该如何显示?
您的请求格式错误,您正在将 1
传递给 preserve_original
参数,该参数只接受异常中提到的 true
和 false
。
除此之外,还有一些问题,例如您使用的 String
数据类型在 v7.1 中已弃用,并且 emails
在 properties
之前出现 JSON.
在我的本地测试正确的映射
{
"settings": {
"analysis": {
"filter": {
"email": {
"type": "pattern_capture",
"preserve_original": true,
"patterns": [
"([^@]+)",
"(\p{L}+)",
"(\d+)",
"@(.+)",
"([^-@]+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"properties": {
"email": {
"type": "text",
"analyzer": "email"
}
}
}
}
谢谢。
我插入了几封电子邮件以使用这个更正后的映射建立索引。
现在,当我搜索特定电子邮件时,我会得到所有结果。 我只想有一个记录。我该怎么做?
http://localhost:9200/test/_search?q=email:abc@abc.net
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 0.21149008,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "0IWQlXcBnPuV0JvQXCHW",
"_score": 0.21149008,
"_source": {
"email": "abc@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "0oWUlXcBnPuV0JvQISFe",
"_score": 0.21149008,
"_source": {
"email": "abc1@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "z4WQlXcBnPuV0JvQNCGn",
"_score": 0.19982167,
"_source": {
"email": "abc2@abc.net"
}
},
{
"_index": "test",
"_type": "_doc",
"_id": "0YWQlXcBnPuV0JvQdiHo",
"_score": 0.19982167,
"_source": {
"email": "abc3@abc.net"
}
}
]
}
}