有什么方法可以汇总Elasticsearch中的前n个结果?

时间:2018-08-10 07:11:39

标签: elasticsearch aggregate

我有一个非常大的数据库,其中包含数百万种产品的数据。在Elastic Search中,我将查询限制为返回前1000个结果,并且希望汇总这些1000个结果。有什么办法吗?我从上周开始尝试这种方法?找不到任何解决方案。这是我的查询。

    'from' => 0,
    'size' => 1000,
    'query' => [
        'bool' => [
            'should' => [
                [
                    'match_phrase' => [
                        'name' => [
                            'query' => $searchQuery,
                            'boost' => 5
                        ]
                    ]
                ],
                [
                    'match' => [
                        'name' => [
                            'query' => $searchQuery,
                            'fuzziness' => "AUTO",
                            "operator" => "or",
                            'boost' => 3
                        ]
                    ]
                ]
            ]
        ]
    ],
      'aggs' => [    
            'company' => [
                 'terms' => [
                     'field' => 'company.raw'
                   ] 
            ]
    ]




    'from' => 0,
    'size' => 1000,
    'query' => [
        'bool' => [
            'should' => [
                [
                    'match_phrase' => [
                        'name' => [
                            'query' => $searchQuery,
                            'boost' => 5
                        ]
                    ]
                ],
                [
                    'match' => [
                        'name' => [
                            'query' => $searchQuery,
                            'fuzziness' => "AUTO",
                            "operator" => "or",
                            'boost' => 3
                        ]
                    ]
                ]
            ]
        ]
    ],
      'aggs' => [    
            'company' => [
                 'terms' => [
                     'field' => 'company.raw'
                   ] 
            ]
    ]

忽略语法。我正在使用某些程序包。我想汇总前1000个结果。我想按公司分组并计数。

1 个答案:

答案 0 :(得分:0)