gpt4 book ai didi

sql - Elasticsearch分组并获得第一记录

转载 作者:行者123 更新时间:2023-12-02 23:10:43 24 4
gpt4 key购买 nike

我是Elastic Search的新手,
我想在 flex 搜索中创建一个查询,该查询的工作方式类似于按SQL分组。
这是我的SQL查询

SELECT top 100  *
FROM (
SELECT ROW_NUMBER()
OVER(PARTITION BY columnA
ORDER BY columnB) AS StRank, *
FROM table where columnA in ('a','b','c') ) n
WHERE StRank IN (1)
GO

我想要按列A和按列B排序的单个行

最佳答案

您可以使用collapse

Allows to collapse search results based on field values. The collapsing is done by selecting only the top sorted document per collapse key


{
"query": {
"bool": {
"filter": {- -> filter doesn't calculate score(if score needed use must)
"terms": {
"columnA": ["a","b","c"]
}
}
}
},
"collapse": { --> top 1 Group by column A
"field": "columnA"
},
"sort": [ --> sort
{
"columnB": {
"order": "desc"
}
}
]
}

关于sql - Elasticsearch分组并获得第一记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60926783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com