例如,在google.com中,有两种类型的搜索结果: 1.与关键字相关的广告;2.正常搜索结果。
在下面的条件下,我如何用弹性搜索来做到这一点呢?
如何做一个单一的查询,将这两个条件集成在一起的搜索结果。
给定样本数据,使用“a”查询,然后返回随机(付费1-3),然后随机(普通4-6)。
{"type" : "paid", "document" : "paid random 1"}
{"type" : "paid", "document" : "paid random 2"}
{"type" : "paid", "document" : "paid random 3"}
{"type" : "normal", "document" : "normal random 4"}
{"type" : "normal", "document" : "normal random 5"}
{"type" : "normal", "document" : "normal random 6"}发布于 2014-08-11 06:11:15
嗨,看看你的问题,我猜你是想去取文件。
因此,我成功地为您提出了一个请求,我使用了命中聚合,
这是我的请求
curl -XPOST "http://localhost:9200/x3/_search" -d'
{
"query": {
"match": {
"doc": "xxx"
}
},
"aggs": {
"tophits_random_paid": {
"top_hits": {
"from": 0,
"size": 3,
"sort": [
{
"paidAmount": {
"order": "desc"
}
},
{
"_script": {
"script": "(doc[\"userid\"].value + salt).hashCode()",
"type": "number",
"params": {
"salt": "some_random_string"
},
"order": "asc"
}
}
]
}
},
"tophits_random_default": {
"top_hits": {
"from": 0,
"size": 3,
"sort": [
{
"_script": {
"script": "(doc[\"userid\"].value + salt).hashCode()",
"type": "number",
"params": {
"salt": "some_random_string"
},
"order": "asc"
}
}
]
}
}
}
}'谢谢,希望这能帮上忙!
https://stackoverflow.com/questions/25229898
复制相似问题