在过去的几个月里,我一直在阅读弹性搜索文档,并继续优化我的查询,但我似乎无法获得低于500-600毫秒的搜索查询 . 在本地数据较少的情况下,我可以在~80-200ms内获得响应 .

概述我要完成的任务:

我在Laravel中有12种不同的型号可以从一个搜索栏中搜索到 . 作为某人的类型,它会被搜索并返回到结果列表中 .

目前,我有这个搜索查询 . 有没有提及我如何改进这个?我查看了multi_match,但是我遇到了部分匹配问题并指定了所有字段 .

$results = $this->elastic->search([
            'index' => config('scout.elasticsearch.index'),
            'type'  => $type ?? implode(',', array_keys($this->permissions, true, true)),
        'body'  => [
            'query' => [
                'bool' => [
                    'must'   => [
                        [
                            'query_string' => [
                                'query' => "$searchQuery*",
                            ],
                        ],
                    ],
                    'filter' => [
                        [
                            'term' => [
                                'account_id' => $accountId,
                            ],
                        ],
                    ],
                    'should' => [
                        [
                            'term' => [
                                '_type' => [
                                    'value' => 'customers',
                                    'boost' => 1.3,
                                ],
                            ],
                        ],
                        [
                            'term' => [
                                '_type' => [
                                    'value' => 'contacts',
                                    'boost' => 1.3,
                                ],
                            ],
                        ],
                        [
                            'term' => [
                                '_type' => [
                                    'value' => 'users',
                                    'boost' => 1.3,
                                ],
                            ],
                        ],
                        [
                            'term' => [
                                '_type' => [
                                    'value' => 'chart_accounts',
                                    'boost' => 1.2,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            'from'  => $from,
            'size'  => $size,
        ],
    ]);