【问题标题】:Elastic Search - Order / Scoring for document of the same user弹性搜索 - 同一用户的文档的排序/评分
【发布时间】:2016-12-24 17:48:14
【问题描述】:

我有一个关于我可以完成某事的问题。 我已经准备好了用户文档的搜索算法。

我获得了文档列表,但我不希望列表中包含同一用户的文档部分。

例如:

doc1: user-1 doc2: user-2 doc3: user-2 doc4: user-3 doc5: user-4

改为:

doc1: user-1 doc2: user-2 doc4: user-3 doc5: user-4 doc3: user-2

某种排序/随机...

关于我可以搜索什么的任何提示和想法? 或者更好,一些例子。

我对弹性搜索很陌生。关于自定义评分或订购的文档很棒,但没有给我正确的答案。

感谢一百万 斯蒂芬

更新 18.08.: 如所愿,这也是我当前的查询。

'query' => [
'filtered' => [
    'query' => [
        'bool' => [
            'must' => [
                'multi_match' => [
                    'query' => $q,
                    'fields' => [ 'title^6', 'description^1', 'tags^3']
                ]
            ], 
            'should' => [
                [
                    'match' => [ 
                        'isTopDocument' => [
                            'query' => 'true',
                            'boost' => 2,
                        ]
                    ]
                ],[
                    'range' => [
                        'online_start' => [
                            'boost' => 1.8,
                            'gte' => 'now-7d/d'
                        ]
                    ]
                ],[
                    'range' => [
                        'online_start' => [
                            'boost' => 1.4,
                            'gte' => 'now-14d/d'
                        ]
                    ]
                ],[ // This is to include all available jobs, at least one should must be true if a must is set
                    // https://www.elastic.co/guide/en/elasticsearch/guide/current/bool-query.html#_controlling_precision
                    'range' => [
                        'online_start' => [
                            'gte' => 'now-61d/d'
                        ]
                    ]
                ]
            ]
        ]
    ],
    'filter' => [
        'bool' => [
            // Some term filters
            'should' => $filter_should,
            'must' => $filter_must,
        ]
    ]
]
],
'size' => $perPage,
'from' => $from

【问题讨论】:

  • 请与问题一起分享您正在使用的查询。

标签: sorting elasticsearch relevance


【解决方案1】:

即使您找到了对这个特定用例进行评分的搜索技巧,您也可能只想考虑对搜索结果进行后处理以获得所需的内容。

只需遍历列表,保留对上一个用户的引用,如果您在下一个结果中看到相同的用户,只需将其从结果中删除,并将其附加到列表的末尾。

一般来说,您会根据需要获得“改组”的用户,偶尔会在列表的最后堆积您最多产的用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 1970-01-01
    • 2015-12-18
    • 2015-03-02
    • 2022-08-12
    • 1970-01-01
    相关资源
    最近更新 更多