pre-indexed shapesを使用すると、ステップ2を間違いなく行うことができます。このソリューションはあらかじめ定義された距離でのみ動作します。
主なアイデアは、次のようになります。
- 各郵便番号と、各事前定義された距離のためにあなたの
locations
インデックスタイプcircle
のgeo_shape
に格納します。
- は、クライアントの場所
- プレインデクス郵便番号形状を活用しまうタイプ
circle
のgeo_shape
クエリを作成するためにあなたのaccounts
インデックスタイプPoint
のgeo_shape
に格納します。
だから、簡単な例として、あなたはこれを持っていると思います:
PUT /locations
{
"mappings": {
"UK_postcode": {
"properties": {
"location": { "type" : "geo_shape" }
}
}
}
}
B.作成し、クライアントの場所インデックス
PUT /accounts
{
"mappings": {
"client": {
"properties": {
"name": { "type": "string" }
"location": { "type" : "geo_shape" }
}
}
}
}
:
A.は、郵便番号の位置のインデックスを作成します。 C."M32 0JG" のために1、2、3マイルの半径のサンプル郵便番号サークルを作成
PUT /locations/UK_postcode/M320JG-1
{
"location": {
"type" : "circle",
"coordinates" : [-2.30283674284007, 53.4556572899372],
"radius": "1mi"
}
}
PUT /locations/UK_postcode/M320JG-2
{
"location": {
"type" : "circle",
"coordinates" : [-2.30283674284007, 53.4556572899372],
"radius": "2mi"
}
}
# ... repeat until radius = 10
D.非常に近いサンプルのクライアントを作成し、 "M32 0JG"
PUT /accounts/client/1234
{
"name": "Big Corp"
"location": {
"type" : "point",
"coordinates" : [-2.30293674284007, 53.4557572899372]
}
}
E.クエリ名前がすべてのクライアントに「ビッグ」と一致し、郵便番号「M32 0JG」の半径2マイルにある人
POST /accounts/client/_search
{
"bool": {
"must": [
{
"match": {
"name": "big" <--- free text name match
}
}
],
"filter": {
"geo_shape": {
"location": {
"indexed_shape": {
"id": "M320JG-2", <--- located within two miles of M32 0JG
"type": "UK_postcode",
"index": "locations",
"path": "location"
}
}
}
}
}
}
出典
2016-05-27 14:17:23
Val
距離は常に同じですか?すなわち、郵便番号の周りを見回しているときは、いつも(例えば)5kmの郵便番号の場所を見ていますか? (私たちは 'geo_distance'を話しているので) – Val
距離は、ユーザーが指定した検索変数です。 –
したがって、「Comp 'で始まり、郵便番号ABC123の周りに11.5kmの名前のクライアントをすべて手に入れますか? – Val