我的 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"
}
}
要根据组件搜索特定地址,我正在考虑以下几点:
为此,我尝试了以下操作:
{
"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"
}
}
]
}
}
您需要使用bool/must/should
查询子句、术语查询(忽略大小写的精确匹配)和match_phrase_prefix查询的组合
索引映射:
{
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"agencycode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"agencyid": {
"type": "long"
},
"branchcode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"branchid": {
"type": "long"
},
"id": {
"type": "long"
},
"postcode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"state": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"streetname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"streetnumber": {
"type": "integer"
},
"suburb": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"unitnumber": {
"type": "integer"
}
}
}
}
搜索查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"streetnumber": "5"
}
},
{
"term": {
"unitnumber": "54"
}
},
{
"bool": {
"should": [
{
"term": {
"streetname.keyword": {
"value": "Burnie Street",
"case_insensitive": "true"
}
}
},
{
"match_phrase_prefix": {
"streetname": "Burnie St"
}
}
]
}
},
{
"term": {
"suburb.keyword": {
"value": "Lyons",
"case_insensitive": "true"
}
}
},
{
"term": {
"postcode.keyword": "2606"
}
},
{
"term": {
"state.keyword": {
"value": "ACT",
"case_insensitive": "true"
}
}
}
]
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句