0
我正在用RubberBand gem在Ruby-on-Rails 2.3應用程序中實現ElasticSearch。我試圖回到方面,但我似乎無法找到可用於此目的的方法。我瀏覽了documentation and source。用橡皮筋雕刻
有誰知道橡皮筋是否可行?
我正在用RubberBand gem在Ruby-on-Rails 2.3應用程序中實現ElasticSearch。我試圖回到方面,但我似乎無法找到可用於此目的的方法。我瀏覽了documentation and source。用橡皮筋雕刻
有誰知道橡皮筋是否可行?
這個問題可能有你在找什麼:
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
}
]
}
}
這正是我一直在尋找,謝謝。 – Denis