Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn a list of top tags for a user
    primarykey
    data
    text
    <p>I'm trying to retrieve a list of the top tags for a User using ElasticSearch and Tire. </p> <p>I've seen <a href="http://www.elasticsearch.org/blog/2011/05/13/data-visualization-with-elasticsearch-and-protovis.html" rel="nofollow">this article</a> floating around, however it doesn't completely work in my situation.</p> <p>I need to filter by a user_id, and am aiming not to get hits returned at all. I haven't found a way of getting this to work with Tire.</p> <p>I have tried the following:</p> <pre><code>Tire.search 'bookmarks' do |s| s.query { all } s.facet 'tags', facet_filter: { term: { user_id: 1 } } do terms :tags, all_terms: true end end </code></pre> <p>Help is appreciated, thank you.</p> <p><strong>EDIT:</strong> Using the code above, the following output is returned.</p> <pre><code>=&gt; #&lt;Tire::Search::Search:0x007fd4b0bed110 @indices=["bookmarks"], @types=[], @options={}, @path="/bookmarks/_search", @query=#&lt;Tire::Search::Query:0x007fd4b0bec5d0 @value={:match_all=&gt;{}}&gt;, @facets={"tags"=&gt;{:terms=&gt;{:field=&gt;:tags, :size=&gt;10, :all_terms=&gt;true}, :facet_filter=&gt;{:term=&gt;{:user_id=&gt;1}}}}&gt; </code></pre> <p><strong>EDIT 2:</strong> I've accomplished what I was trying to do with the following code:</p> <pre><code># Public: Returns an array of hashes, which includes the user's top # tags and a number of items in those tags. # # Format follows: # [{'term' =&gt; 'Some Tag', 'count' =&gt; 123}, {'term' =&gt; 'Another Tag', 'count' =&gt; 321}] # def self.top_tag_count(user_id, number_of_tags=10) top_tags = tire.search search_type: 'count' do |s| s.query { all } s.filter :term, user_id: [user_id] s.facet 'tags', global: true do terms :tags, size: number_of_tags end end top_tags.facets['tags']['terms'] end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload