【发布时间】:2014-06-06 00:09:46
【问题描述】:
有没有办法根据 _score 只提取在某个字段中具有相同值的文档的前 2 个结果?
此过滤器或聚合之前的点击数如下:
{
"_index":"myindex",
"_score":100,
"_source": {
"myfield1": "i have a twin",
"name":"fred"
}
},
{
"_index":"myindex",
"_score":50,
"_source": {
"myfield1": "i have a twin",
"name":"george"
}
},
{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i have a twin",
"name":"tom"
}
},
{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i DONT have a twin",
"name":"doug"
}
}
然后在此过滤器/聚合之后,我希望删除此 ... tom,因为他对 myfield1 具有相同的值,但得分最低。 Doug 留下来是因为他对 myfield1 的价值观不同。
{
"_index":"myindex",
"_score":100,
"_source": {
"myfield1": "i have a twin",
"name":"fred"
}
},
{
"_index":"myindex",
"_score":50,
"_source": {
"myfield1": "i have a twin",
"name":"george"
}
},
{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i DONT have a twin",
"name":"doug"
}
}
我希望这会产生正确的效果......但它没有。我接近了吗?
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"myfield1": {
"query": "i have",
"fuzziness": 1,
"slop": 2,
"max_expansions": 10,
"prefix_length": 1
}
}
}
]
}
},
"boost_mode": "replace",
"functions": [
{
"script_score": {
"script": "_score * [...] "
}
}
]
}
},
"aggs": {
"myfield1": {
"terms": {
"field": "myfield1",
"size": 2,
"order": {
"max_score": "desc"
}
},
"aggs": {
"max_score": {
"max": {
"field": "_doc.score"
}
}
}
}
}
}
【问题讨论】:
标签: search lucene elasticsearch search-engine