【发布时间】:2014-06-25 12:42:24
【问题描述】:
我目前正忙于一个项目,我们选择使用 Elasticsearch 作为分类网站的搜索引擎。
目前,我有以下业务规则:
每页列出 25 个广告。在这 25 个中,显示的广告中有 10 个必须是“付费广告”,另外 15 个必须是“免费”。所有 25 项都必须与执行的搜索相关(即关键字、地区、价格、类别等)
我知道我可以使用两个单独的查询来做到这一点,但这似乎是对资源的极大浪费。是否可以进行“子查询”(如果您可以这样称呼它们?)并将这些结果合并到一个结果集中?不知何故,在一个查询中只能从弹性搜索中获取 10 个“付费”广告和 15 个“免费”广告?当然,假设有足够多的广告使这个要求成为可能。
感谢您的帮助!
编辑 - 只需添加我的地图信息以提高清晰度。
"properties": {
"advertText": {
"type": "string",
"boost": 2,
"store": true,
"analyzer": "snowball"
},
"canonical": {
"type": "string",
"store": true
},
"category": {
"properties": {
"id": {
"type": "string",
"store": true
},
"name": {
"type": "string",
"store": true
},
"parentCategory": {
"type": "string",
"store": true
}
}
},
"contactNumber": {
"type": "string",
"index": "not_analyzed",
"store": true
},
"emailAddress": {
"type": "string",
"store": true,
"analyzer": "url_email_analyzer"
},
"advertType": {
"type": "string",
"index": "not_analyzed"
},
...
}
然后我想要的是能够查询并获得 10 个结果,其中“advertType”:“付费”和 15 个“advertType”:“免费”...
【问题讨论】:
-
您能分享您的映射、示例数据和每种类型的示例查询吗?对提出解决方案有很大帮助。
-
@JohnPetrone,我会在我回来工作时这样做(在 RSA 是晚上 8 点)。尽管如此,让我们将“广告”的概念完全排除在外,是否可以查询弹性搜索一次,但执行类似“获得 5 个 admins 和 10 个 people 索引中的 i>员工?我不知道如何用恰当的措辞来表达这个问题,这样才更有意义!
-
我想我可以让你非常接近 - 我会开始写一个答案。需要一点解释。
标签: php elasticsearch elastica