gpt4 book ai didi

ruby-on-rails - 有没有一种方法可以获取过滤器的点击次数,而无需返回过滤器的所有结果

转载 作者:行者123 更新时间:2023-12-02 23:06:29 25 4
gpt4 key购买 nike

使用 flex 搜索,我试图使用过滤器来计算两个关联模型中的链接数。

我的问题有很多票。

我有一个选票映射,它为每个选票的问题ID编制索引,并且正在做

curl -XGET localhost:9200/votes/_search -d '{query : {"constant_score" : {"filter" : { "term" : {"question_id" : 5} }, "boost" : 1.0 } }}'

问题在于这将返回所有结果。是否可以简单地获取计数?

最佳答案

只需将search_type=count添加到您的查询字符串中:

curl -XGET localhost:9200/votes/_search?search_type=count -d '{
"query" : {
"constant_score" : {
"filter" : { "term" : {"question_id" : 5} }
}
}
}'

就是说,正如@phoet所建议的那样,您可能想要使用构面。

例如,对于前10个问题:
curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count'  -d '
{
"facets" : {
"votes" : {
"terms" : {
"field" : "question_id"
}
}
}
}
'

或者仅是question_id 5:
curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count'  -d '
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"question_id" : 5
}
}
}
},
"facets" : {
"votes" : {
"terms" : {
"field" : "question_id"
}
}
}
}
'

关于ruby-on-rails - 有没有一种方法可以获取过滤器的点击次数,而无需返回过滤器的所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8740497/

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