2013-08-05 119 views
1

我试图在我的公共传输算法中实现Elasticsearch以获取GTFS数据,但不知道什么是“最佳”方式来获取我需要的数据(注意:我在C#中使用NEST)。多类型ElasticSearch搜索请求NEST C#

我已收录2类:

public class StopTimes : IGTFS 
{ 
    public string trip_id; 
    public string arrival_time; 
    public string departure_time; 
    public string stop_id; 
    public string stop_sequence; 
    public string stop_headsign; 
    public string shape_dist_traveled; 
} 

public class Trips : IGTFS 
{ 
    public string route_id; 
    public string service_id; 
    public string trip_id; 
    public string trip_head_sign; 
    public string trip_short_name; 
    public string direction_id; 
    public string shape_id; 
} 

我想知道如何我可以从stop_id,让所有的相应route_id在一个简单的请求(停止可以属于多个路由)。

目前,我试图做到这一点在2个步骤知道一个stop_id可以在几个StopTimes和几个trip_id s内匹配属于一个route_id(我有6K trip_id S代表8个route_id S)。

  • 我让所有的StopTimes(超过2K点击)数据,其中stop_id比赛。

     var result = _client.Search(s => s 
         .Index("gtfs_data") 
         .Type("stoptimes") 
         .Fields("trip_id") 
         .Query(q => q 
          .Term("stop_id", id)).Size(10000000) 
         ); 
    
  • 然后我试图让旅行中的route_id,但我真的不知道如何进行(面?)

    var result2 = _client.Search<Trips>(s => s 
           .Index(_ratpData) 
           .Query(q => q 
           .Terms(t => t.trip_id, terms)) //terms = array of stop_id 
           .FacetTerm(t=>t 
            .OnField(f=>f.route_id).Size(10000000)) 
           ); 
    

感谢您的帮助:)

回答

0

如果这是您的数据编制索引的方式,那么您的第一个查询听起来也需要是一个方面 - 您需要stop_id的所有trip_ids,以便您需要trip_id上的方面(并且不要将所有实际stoptimes)。 然后下一个查询就像你指定的那样是一个关于route_id的方面。 确保将您的搜索类型设置为计数以提高性能(http://www.elasticsearch.org/guide/reference/api/search/search-type/)。

如果trip_id始终属于单个route_id,则另一个选项是使用Trips和StopTime之间的父子关系。您将Trip设置为映射中StopTime的父级(http://www.elasticsearch.org/guide/reference/mapping/parent-field/),将每个停留时间的索引作为其父级,然后可以使用has_child查询或过滤器(http://www.elasticsearch.org/guide/reference/query-dsl/has-child-query/)将所有Trips(route_ids)一定的stop_id。

+0

谢谢你的回答,我没有想过父母,我会试试这种方式:) – Orelus

相关问题