2013-05-15 73 views
0

我正在用RubberBand gem在Ruby-on-Rails 2.3应用程序中实现ElasticSearch。我试图回到方面,但我似乎无法找到可用于此目的的方法。我浏览了documentation and source用橡皮筋雕刻

有谁知道橡皮筋是否可行?

回答

0

这个问题可能有你在找什么:

https://github.com/grantr/rubberband/issues/4

q = { 
    "query"=> { 
    "filtered"=> { 
     "query"=> { 
     "match_all"=> {} 
     }, 
     "filter"=> { 
     "term"=> { 
      "client_id"=> "717", 
      "product_id"=> "1" 
     } 
     } 
    } 
    }, 
    "facets"=> { 
    "shipped_to_state_counts"=> { 
     "terms"=> { 
     "field"=> "state", 
     "size"=> "500" 
     } 
    } 
    } 
} 

编辑:(简单的查询,Lucene的语法)

注意:这些是不一样的查询, per elasticsearch documentation:

要记住一个重要的区别。虽然搜索 queries限制了返回的文档和构面计数,但搜索 filters仅限制返回的文档 - 但不包括构面计数。

q = { 
    "query"=> { 
    "query_string"=> { 
     "query"=> "client_id:717 AND product_id:1" 
    } 
    }, 
    "facets"=> { 
    "shipped_to_state_counts"=> { 
     "terms"=> { 
     "field"=> "state", 
     "size"=> "500" 
     } 
    } 
    } 
} 

编辑完

results = client.search(q) 
facets = results.facets 

=> 
{ 
    "shipped_to_state_counts"=> { 
    "_type"=> "terms", 
    "missing"=> 0, 
    "total"=> 1873274, 
    "other"=> 0, 
    "terms"=> [ 
     { 
     "term"=> "MO", 
     "count"=> 187327 
     }, 
     { 
     "term"=> "FL", 
     "count"=> 17327 
     } 
    ] 
    } 
} 
+0

这正是我一直在寻找,谢谢。 – Denis