我正在使用RubberBand gem在Ruby-on-Rails 2.3应用程序中实现ElasticSearch。我试图返回方面,但我似乎无法找到我可以用于此目的的方法。我查看了documentation and source。
有人知道橡皮筋是否可行?
答案 0 :(得分: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语法)
注意:根据elasticsearch文档,这些查询不同:
要记住一个重要的区别。在搜索时
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
}
]
}
}