【发布时间】:2020-11-10 05:56:21
【问题描述】:
在 ElasticSearch 中,我有一个电子邮件字段和标题字段的映射,如下所示:
{
"person": {
"mappings": {
"_doc": {
"email": {
"type": "keyword",
"boost": 80
},
"title": {
"type": "text",
"boost": 70
}
}
}
}
每个人可以拥有多个电子邮件地址和职位。所以,我将值存储在数组中。 我使用 query_string 来搜索具有电子邮件地址和/或头衔的人。电子邮件地址需要完全匹配。
我已使用以下数据为文档编制索引。在 Kibana 中调用 GET person/_search 将在结果中生成以下文档。
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "person",
"_type": "_doc",
"_id": "101",
"_score": 1,
"_source": {
"title": """["Actor", "Hero", "Model"]""",
"email": """["jdepp@hotmail.com", "johnny@hollywood.com", "jdepp@gmail.com", "johnny.depp@yahoo.com"]""",
"SEARCH_ENTITY": "PERSON"
}
}
]
}
}
现在,当我添加一些电子邮件搜索参数时,我不会在结果中返回文档。记住电子邮件是关键字类型。
请求:
GET person/_search
{
"query" : {
"query_string" : {
"query" : "SEARCH_ENTITY:PERSON AND (email: (johnny.depp@yahoo.com))"
}
}
}
回复:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
但同样的查询也适用于文本类型的标题字段。
请求:
GET person/_search
{
"query" : {
"query_string" : {
"query" : "SEARCH_ENTITY:PERSON AND (title: ((actor)))"
}
}
}
回复:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 20.137747,
"hits": [
{
"_index": "person",
"_type": "_doc",
"_id": "101",
"_score": 20.137747,
"_source": {
"ID": "101",
"title": """["Actor", "Hero", "Model"]""",
"email": """["jdepp@hotmail.com", "johnny@hollywood.com", "jdepp@gmail.com", "johnny.depp@yahoo.com"]"""
}
}
]
}
}
有人可以告诉我我需要做什么才能使这项工作适用于关键字类型的电子邮件字段吗?
注意:如果我只存储一个电子邮件地址而不使用数组,它可以正常工作。
谢谢。
【问题讨论】:
标签: elasticsearch kibana elasticsearch-6.5