2016-07-18 7 views
3

クエリ対象オブジェクト(MyObject)内の配列にネストされているオブジェクト(Location)にネストされているgeo_point(geo_coordinates)に対してフィルタリングしようとしています。
問題は、オブジェクトMyObjectにのためのマッピングはgeo_pointとしてgeo_coordinatesフィールドを見ていないということです。入れ子オブジェクトの配列内のgeo_pointに対するフィルタ

// Index mapping for object MyObject 
"myobjects": { 
    "mappings": { 
     "myobject": { 
     "properties": { 
      "locations": { 
      "type": "nested", 
      "include_in_parent": true, 
      "properties": { 
       "geo_coordinates": { 
       "properties": { 
        "lat": { "type": "double" }, 
        "lon": { "type": "double" } 
       } 
       }, 
    } 
[...] 
// Index mapping for object Location 
"locations": { 
    "mappings": { 
     "location": { 
     "properties": { 
      "geo_coordinates": { 
      "type": "geo_point" 
      }, 
     } 
     } 
    } 

マングースオブジェクトMyObjectには、次のようになります。

var MyObjectSchema = new Schema(
[...] 
    locations: { 
     type: [{ type: Schema.Types.ObjectId, ref: 'Location', es_schema: LocationSchema.schema}], 
     es_type: 'nested', 
     es_include_in_parent: true 
    }, 
[...] 
) 

マングースオブジェクトの場所のように見えますこの:

var LocationSchema = new Schema(
[...] 
    geo_coordinates: { 
     type: { 
     geo_point: { 
      type: String, 
      es_type: 'geo_point', 
      es_lat_lon: true 
     }, 

     lat: {type: Number, default: 0}, 
     lon: {type: Number, default: 0} 
     }, 
     es_type: 'geo_point' 
    } 
[...] 
); 

私のクエリは次のようになります。

// POST http://ES-endpoint/locations/_search 
{ 
    "query": { 
     "filtered" : { 
      "query": { 
        "match_all" : {} 
       }, 
       "filter" : { 
        "geo_distance" : { 
         "distance" : "20000km", 
         "locations.geo_coordinates" : { 
          "lat" : 40, 
          "lon" : -70 
         }}}}}} 

私は何かを欠場する必要がありますが、何ですか?
PS:Kibanaと索引を探索する場合、両方のオブジェクトがgeo_locationに対して同じデータを持っている:

"geo_coordinates": { 
      "lat": x.xxxx, 
      "lon": y.yyy 
     } 

答えて

2

後、ネストされたオブジェクトにgeo_pointに対してフィルタクエリを適用する上での例です。私はmongoosasticを使って、elasticsearchで索引付けを作成するMongooseプラグインです。

マングースジオロケーションデータモデル

geoLocation: { 
    type: { 
     type: String, 
     default: 'Point' 
    }, 
    coordinates: [Number] 
} 

Model.createMapping({ 
      "mappings": { 
       "event": { 
        "properties": { 
         "geoLocation": { 
          "type": "nested", 
          "properties": { 
           "coordinates": { 
            "type": "geo_point", 
            "lat_lon": true 
           } 
          } 
         } 
        } 
       } 
      } 
     }, 
     function(err, mapping) { 
      if (!err) { 
       console.log('mapping created!'); 
      } 
     }); 

クエリ地理フィルターとジオロケーションフィールドにマッピングを作成します

{ 
    "query": { 
     "filtered": { 
      "query": { 
       "multi_match": { 
        "query": "Pop", 
        "fields": ["name","city"], 
        "type": "phrase_prefix" 
       } 
      }, 
      "filter": { 
       "nested": { 
        "path": "geoLocation", 
        "query": { 
         "filtered": { 
          "filter": { 
           "geo_distance": { 
            "distance": "5km", 
            "geoLocation.coordinates": { 
             "lat": 19.1074861, 
             "lon": 72.9156988 
            } 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 
関連する問題