gpt4 book ai didi

laravel - 带有静态字段值的Elasticsearch multi_query

转载 作者:行者123 更新时间:2023-12-03 02:33:16 24 4
gpt4 key购买 nike

我已经遵循this tutorial来让Elasticsearch与Laravel 6一起工作。一切都很好,但是我需要对查询进行一些更改。我需要对此进行更改:

private function searchOnElasticsearch(string $query = '', int $fooId = 3): array
{
$model = new Customer;

$items = $this->elasticsearch->search([
'index' => $model->getSearchIndex(),
'type' => $model->getSearchType(),
'body' => [
'query' => [
'multi_match' => [
'type' => 'best_fields',
'fields' => ['FirstName^5', 'Surname^5'],
'query' => $query,
// I need to include this:
// fields ['foo_id' => $fooId]
],
],
],
]);

return $items;
}

本质上,这基于 query查询整个模型。我不想要那个。用户只能基于列的值返回数据。假设该模型称为 Customers。在客户表上,一个名为 foo_id的字段。我需要类似的搜索:

Customer::query()
->whereRaw("UPPER(field) LIKE '%". strtoupper($query)."%' AND foo_id =" . 3)

如何在 multi_match中包含静态字段值?我看过 the docs,但似乎没有任何作用?

最佳答案

如果有人正在寻找类似的答案:

/** Optional to limit number of results returned:
* "from" => 0,
* "size" => 5,
*/
"query" => [
"bool" => [
"must" => [
["match" => ["foo_id" => 3]], // static value
[
"multi_match" => [
"query" => $query,
"type" => "cross_fields",
"operator" => "or",
"fields" => [
"FirstName",
"Surname",
// .. other fields
],
"minimum_should_match" => "2",
]
],
]
]
]
],

关于laravel - 带有静态字段值的Elasticsearch multi_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59466955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com