ranking

How to paging aggregation result in ElasticSearch?

和自甴很熟 提交于 2019-12-11 12:53:29
问题 When I execute the query below, how to paging the aggs results? And is there a method to put the aggs results to hits part in json result? POST http://myElastic.com/test/e1,e2,e3/_search { "aggs":{ "dedup" : { "terms":{ "field": "id" }, "aggs":{ "dedup_docs":{ "top_hits":{ "size":1 } } } } } } 回答1: Based on the below issue on the Elasticsearch github site I don't think what you are asking for is possible: https://github.com/elastic/elasticsearch/issues/4915 Seems like a common request however

MySQL- Trigger updating ranking

孤街浪徒 提交于 2019-12-11 12:37:59
问题 I'm creating a DB with "Team" table for some NFL teams, and I have assigned them all a ranking (standing in NFL), the attribute is called "Ranking". I want to create a trigger such that if the ranking is updated, all of the others are updated appropriately. However, I can't figure out a way to loop through the table. For example, assume team at rank 5 moves up to rank 3, how do I get the rank 3 to become 4, and then 4 to be 5? If you need more info, feel free to ask, I'll provide it ASAP. 回答1

Recognizing duplicates while iterating through query results

送分小仙女□ 提交于 2019-12-11 11:09:20
问题 This is a follow-up to a question I asked previously. I can calculate the rank (including the logic for ties) just fine; the issue is detecting future duplicates when I come across the first instance of a duplicate rank. Here is the SQL query to get the result set: SELECT s1.team_id, sum(s1.score>s2.score) wins FROM scoreboard s1 LEFT JOIN scoreboard s2 ON s1.year=s2.year AND s1.week=s2.week AND s1.playoffs=s2.playoffs AND s1.game_id=s2.game_id AND s1.location<>s2.location GROUP BY s1.team_id

How to output different 25th, 50th, 75th percentiles in single Teradata query?

。_饼干妹妹 提交于 2019-12-11 08:38:08
问题 I had got stuck few hours back on around something similar and worked out a less messy code for outputting 25th, 50th, 75th percentiles in a single Teradata query. Can be further extended to produce a " 5 point summary ". For minimum and maximum change static values according to your population estimate. Somewhere someone had asked for an elegant approach. Sharing mine. Here's the code: SELECT MAX(PER_MIN) AS PER_MIN, MAX(PER_25) AS PER_25, MAX(PER_50) AS PER_50, MAX(PER_75) AS PER_75, MAX

sql show partition based on calculated column with mysql

柔情痞子 提交于 2019-12-11 08:36:10
问题 Let's pretend we have this relation: ╔═══════════════════╗ ║ i++ name score ║ ╠═══════════════════╣ ║ 1 Will 123 ║ ║ 2 Joe 100 ║ ║ 3 Bill 99 ║ ║ 4 Max 89 ║ ║ 5 Jan 43 ║ ║ 6 Susi 42 ║ ║ 7 Chris 11 ║ ║ 8 Noa 9 ║ ║ 9 Sisi 4 ║ ╚═══════════════════╝ Now I need a subset based on the data I am searching for. For instance I'm searching for the fith place. In my result I need more than the record of Jan, I need the two records before Jan and the two records behind Jan too. So I have the following

Determining an a priori ranking of what sites a user has most likely visited

雨燕双飞 提交于 2019-12-11 06:51:15
问题 This is for http://cssfingerprint.com I have a largish database (~100M rows) of websites. This includes both main domains (both 2LD and 3LD) and particular URLs scraped from those domains (whether hosted there [like most blogs] or only linked from it [like Digg], and with a reference to the host domain). I also scrape the Alexa top million, Bloglines top 1000, Google pagerank, Technorati top 100, and Quantcast top million rankings. Many domains will have no ranking though, or only a partial

MYSQL update statement to backfill ranking by each id

元气小坏坏 提交于 2019-12-11 06:17:59
问题 I was trying to implement a query, that for each userid, rank the score and backfill the rank field, so that id | score | rank 1 | 100 | 0 1 | 200 | 0 1 | 300 | 0 2 | 100 | 0 2 | 200 | 0 3 | 200 | 0 will become id | score | rank 1 | 100 | 3 1 | 200 | 2 1 | 300 | 1 2 | 100 | 2 2 | 200 | 1 3 | 200 | 1 I saw a similar question here MySQL update statement to store ranking positions However, in my case, how can I do the 'group by id' for each id? 回答1: It might not be the prettiest way, but you can

Optimize slow ranking query

China☆狼群 提交于 2019-12-11 05:53:51
问题 I need to optimize a query for a ranking that is taking forever (the query itself works, but I know it's awful and I've just tried it with a good number of records and it gives a timeout). I'll briefly explain the model. I have 3 tables: player, team and player_team. I have players, that can belong to a team. Obvious as it sounds, players are stored in the player table and teams in team. In my app, each player can switch teams at any time, and a log has to be mantained. However, a player is

Allow users to rate a comment once PHP MySQL

你离开我真会死。 提交于 2019-12-11 05:30:08
问题 I have a website where users can rate comments that are left on pages. Each comment has a unique ID (E.g. 402934) If I want users to be able to thumb-up/thumb-down said comments I can see how I would make a simple counter code to keep track of the number of thumb-ups vs thumb-downs but how can I make sure that each user only ranks said comment once. I was going to make a database with each comment number as a row and in that row having an array of all the users that have ranked it thumbs up

Improve ranking times on multiple JSONB fields search in PostgreSQL

a 夏天 提交于 2019-12-11 04:45:46
问题 My search times are actually quite fast now but as soon as I start to rank them for the best results I hit a wall. The more hits I get, the slower it gets. For uncommon terms the search takes ~2ms and for more common ones it's ~900ms+. In the example I have gathered all possible structures within my data (simple, arrays, nested arrays). CREATE TABLE book ( id BIGSERIAL NOT NULL, data JSONB NOT NULL ); Then I build a function which concatenate the name values of my nested array field 'author':