请注意:
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
邮编与结构化数据编辑
我们会使用美国目前使用的邮编形式(United Kingdom postcodes 标准)来说明如何用部分匹配查询结构化数据。
这种邮编形式有很好的结构定义。例如,邮编 W1V 3DG 可以分解成如下形式:
W1V:这是邮编的外部,它定义了邮件的区域和行政区:-
W代表区域( 1 或 2 个字母) -
1V代表行政区( 1 或 2 个数字,可能跟着一个字符)
-
3DG:内部定义了街道或建筑:-
3代表街区区块( 1 个数字) -
DG代表单元( 2 个字母)
-
假设将邮编作为 not_analyzed 的精确值字段索引,所以可以为其创建索引,如下:
PUT /my_index
{
"mappings": {
"address": {
"properties": {
"postcode": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}PUT /my_index/address/1
{ "postcode": "W1V 3DG" }
PUT /my_index/address/2
{ "postcode": "W2F 8HW" }
PUT /my_index/address/3
{ "postcode": "W1F 7HW" }
PUT /my_index/address/4
{ "postcode": "WC1N 1LZ" }
PUT /my_index/address/5
{ "postcode": "SW5 0BE" }现在这些数据已可查询。
Getting Started Videos
备份地址:http://www.lvesu.com/blog/es/_postcodes_and_structured_data.html