2016-04-08 2 views
2
作ることができます

私のスキーマはマングースのために次のようになります。Mongoosastic、どのように私はジオの距離クエリ

var articleSchema = new Schema({ 
    Name: {type: String, es_indexed: true},   
    geo_with_lat_lon: { 
     geo_point: { 
      type: String, 
      es_type: 'geo_point', 
      es_lat_lon: true 
     }, 
     lat: {type: Number}, 
     lon: {type: Number} 
    }, 
    ... 
}); 

私は新しいドキュメントを追加:

var artikel = new global.DBModel.article({ 
     Name:"Test", 
     geo_with_lat_lon:{lon:-70,lat:40} 
}); 
artikel.save(...); 

今私がでフィルタリングしたいと思いますが距離。私のクエリは次のようになります。

global.DBModel.article.search({ 
     "bool": { 
      "must": { 
       "match_all": {} 
      }, 
      "filter" :{ 
       "geo_distance": { 
        "distance": "200km", 
        "geo_with_lat_lon": { 
         "lat": 40, 
         "lon": -70 
        } 
       } 
      } 
     } 
    }, {...} 

しかし、私は常にエラーに

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "query_parsing_exception", 
      "reason": "failed to find geo_point field [geo_with_lat_lon]", 
      "index": "articles", 
      "line": 1, 
      "col": 127 
     } 
     ], 
     "type": "search_phase_execution_exception", 
     "reason": "all shards failed", 
     "phase": "query", 
     "grouped": true, 
     "failed_shards": [ 
     { 
      "shard": 0, 
      "index": "articles", 
      "node": "YdQHw7nSRc-T0LwItupmmw", 
      "reason": { 
      "type": "query_parsing_exception", 
      "reason": "failed to find geo_point field [geo_with_lat_lon]", 
      "index": "articles", 
      "line": 1, 
      "col": 127 
      } 
     } 
     ] 
    }, 
    "status": 400 } 

を取得する私の質問は:どのように私は距離によって正しくフィルタリングすることができますか?

+0

は問題があなたのフィルタについてのが、あなたのマッピングに関するものではありません。あなたのelasticsearchデータベースで 'geo_with_lat_lon'のタイプを確認できますか? – Paradise228

+0

回答には[SOスレッド](http://stackoverflow.com/questions/30500454/geocode-filter-in-mongoose-elasticsearch)をフォローすることができます – Paradise228

答えて

1

ありがとうParadise228、それはマッピングでした。

この作品:このマッピングで

...geo_with_lat_lon: { 
     geo_point: { 
      es_indexed: true, 
      type: String, 
      es_type: 'geo_point', 
      es_lat_lon: true 
     }, 
     lat: {type: Number}, 
     lon: {type: Number} 
    },... 

global.DBModel.store.createMapping(function (err, mapping) { 
    if (err) { 
     console.log('error creating mapping (you can safely ignore this)'); 
     console.log(err); 
    } else { 
     console.log('mapping created!'); 
     console.log(mapping); 
    } 
}); 
関連する問題