【发布时间】:2016-02-20 01:01:31
【问题描述】:
我有一个有效的 Elasticsearch 查询,如下所示:
{
"index": "event",
"type": "item",
"body": {
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "party",
"type": "phrase_prefix",
"fuzziness": null,
"fields": [
"label^2",
"excerpt",
"body"
]
}
},
"filter": {
"bool": {
"must": [
{
"term": {
"is_deleted": false
}
},
{
"term": {
"is_private": false
}
},
{
"range": {
"date_start": {
"gt": "now"
}
}
}
]
}
}
}
}
}
}
此查询搜索与关键字搜索匹配的事件,这些事件将在未来开始,并过滤掉任何标记为已删除或私有的事件。
每个可以创建活动的用户也可以向系统购买套餐。我想提升包裹价值更高的用户。我确定我需要使用 Function Score Query 实现自定义评分功能,但我无法理解文档,盲目地尝试它不会让我有任何收获。
例如,索引文档可能如下所示:
[
{
"label": "My Birthday Party",
"excerpt": "Come celebrate with me as I turn 30",
"body": "I'm turning 30 soon, let's go dancing!",
"date_start": "2016-06-19",
"is_deleted": false,
"is_private": false,
"user": {
"id": 1,
"name": "Pablo",
"package": {
"id": 14,
"cost": "1000",
"label": "The \"£10 per month\" package"
}
}
},
{
"label": "House Warming Party",
"excerpt": "I moved house, help me decorate it",
"body": "I love my new house, but it's empty and I have no furniture.",
"date_start": "2016-04-19",
"is_deleted": false,
"is_private": false,
"user": {
"id": 2,
"name": "Gary",
"package": {
"id": 15,
"cost": "5000",
"label": "The \"£50 per month\" package"
}
}
}
]
在返回这两个结果的查询中,基于 Gary 的包裹具有更高价值(即user.package.cost)这一事实,我如何将可怜的 Gary(需要帮助装饰)优先于 Pablo 的生日。
在其他相等的搜索中,Gary 的结果必须排在第一位。
任何指针?
谢谢。
【问题讨论】:
标签: elasticsearch