【发布时间】:2021-09-27 22:49:33
【问题描述】:
我的 elasticSearch 中存储了带有地址组件的地址,每个地址在我的 ES 中如下所示:
{
"_index": "properties",
"_type": "_doc",
"_id": "property_5235354",
"_score": 32.839436,
"_source": {
"id": 5235354,
"branchid": 1,
"suburb": "Lyons",
"postcode": "2606",
"state": "ACT",
"@timestamp": "2021-09-27T08:56:08.827Z",
"agencycode": "X",
"address": "54-5 Burnie St Lyons ACT 2606 AUS",
"streetnumber": "5",
"branchcode": "X_ACT",
"unitnumber": "54",
"agencyid": 1,
"streetname": "Burnie St",
"@version": "1"
}
}
要根据组件搜索特定地址,我正在考虑以下几点:
- 可能有街道名称的缩写,例如“James Street”->“James St”
- 以不区分大小写的方式精确匹配的地址组件匹配
- 如果您认为我应该考虑其他事情,请告诉我
为此,我尝试了以下操作:
{
"query": {
"bool": {
"should": [
{
"match": {
"streetname.keyword": "Burnie Street"
}
},
{
"match": {
"streetname.keyword": "Burnie St"
}
}
],
"must": [
{
"match": {
"unitnumber.keyword": "54"
}
},
{
"match": {
"streetnumber.keyword": "5"
}
},
{
"match": {
"suburb.keyword": "Lyons"
}
},
{
"match": {
"state": "ACT"
}
},
{
"match": {
"postcode.keyword": "2606"
}
}
]
}
},
"size": 1000
}
需要您的帮助来解决这些问题:
- 上述查询也返回无效结果,例如地址:
54-5 Burnie Avenue Lyons ACT 2606 AUS这是伯尼大道而不是伯尼街。 - 如果我给
burnie street而不是Burnie Street,则无法找到数据。
更多信息:
这是带有上述请求正文的 _search API 的完整结果,其中地址 54-5 Burnie St Lyons ACT 2606 AUS 和 54/5 Burnie Street Lyons ACT 2606 正确匹配,但 54-5 Burnie Avenue Lyons ACT 2606 AUS 是无效匹配
{
"took": 1476,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 32.839436,
"hits": [
{
"_index": "properties",
"_type": "_doc",
"_id": "property_5235354",
"_score": 32.839436,
"_source": {
"id": 5235354,
"branchid": 1,
"suburb": "Lyons",
"postcode": "2606",
"state": "ACT",
"@timestamp": "2021-09-27T08:56:08.827Z",
"agencycode": "X",
"address": "54-5 Burnie St Lyons ACT 2606 AUS",
"streetnumber": "5",
"branchcode": "X_ACT",
"unitnumber": "54",
"agencyid": 1,
"streetname": "Burnie St",
"@version": "1"
}
},
{
"_index": "properties",
"_type": "_doc",
"_id": "property_11081",
"_score": 28.954222,
"_source": {
"id": 11081,
"branchid": 1,
"suburb": "Lyons",
"postcode": "2606",
"state": "ACT",
"@timestamp": "2021-09-27T08:56:08.163Z",
"agencycode": "X",
"address": "54/5 Burnie Street Lyons ACT 2606",
"streetnumber": "5",
"branchcode": "X_ACT",
"unitnumber": "54",
"agencyid": 1,
"streetname": "Burnie Street",
"@version": "1"
}
},
{
"_index": "properties",
"_type": "_doc",
"_id": "property_5235356",
"_score": 22.677355,
"_source": {
"id": 5235356,
"branchid": 1,
"suburb": "Lyons",
"postcode": "2606",
"state": "ACT",
"@timestamp": "2021-09-27T08:56:08.847Z",
"agencycode": "X",
"address": "54-5 Burnie Avenue Lyons ACT 2606 AUS",
"streetnumber": "5",
"branchcode": "X_ACT",
"unitnumber": "54",
"agencyid": 1,
"streetname": "Burnie Avenue",
"@version": "1"
}
}
]
}
}
【问题讨论】:
-
如果它有助于 SQL 中的相同查询:select * from properties p where streetnumber = '5' and unitnumber = '54' and (streetname = 'Burnie Street' or streetname = 'Burnie St' ) 和郊区 = '里昂' 和邮政编码 = '2606' 和州 = 'ACT'
-
请注意,它是 Elasticsearch,而不是 elasticSearch :)
标签: elasticsearch