php - 如何从laravel Controller 传递搜索查询到elasticsearch?

标签 php laravel elasticsearch

我想将嵌套查询从我的laravel Controller 传递给elasticsearch。
我的简单查询就像

简单查询

$params = [
            'index' => 'my_index',
            'type' => 'product',
            'body' => [
                    'query'=>[
                        'match'=>[
                            'title'=>'first'
                        ]
                    ]
                ]
            ];
        $response = \Es::Search($params); //passing query from here

它工作完美。

如何将以下嵌套查询传递给\Es::Search($params);

我的嵌套查询:
{   
 "query": {
    "nested": {
      "path": "sku",
      "query": {
        "bool": {
          "must": [
            { "match": {"sku.price": "50"}}
          ]
        }
      }
    }   
  }
}

我是Elasticsearch的新手,请提出一些建议。

最佳答案

您可以传递嵌套搜索查询,例如:

$params = [
        'index' => 'my_index',
        'type' => 'product',
        'body' => [
                'query'=>[
                'nested'=> [
                    'path'=> 'category',
                        'query'=> [
                            'bool'=> [
                                'must'=> [
                                    'match'=>[
                                        'category.title'=> $catagory
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ];
    $response = \Es::Search($params); 

希望对您有所帮助。

关于php - 如何从laravel Controller 传递搜索查询到elasticsearch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35665879/

相关文章:

php - Symfony Controller 中的 json_decode ?

Git 从另一个没有历史记录的存储库中 pull

php - Eloquent groupBy 在 Laravel 5.3 中使用有效的 SQL 查询生成 "SQLSTATE[42000]"

elasticsearch - 弹性文档日期比较问题

python - 如何使用 Python 查找文本中的公司名称

php - SaaS 的身份验证

php artisan Schedule :run, 没有计划的命令准备好运行,不知道为什么?

elasticsearch - 范围查询中的 Java 高级 Rest 客户端内存使用情况

php - 带有 ñ 或重音符号的友好 Url 问题字符串

php - Laravel Valet 不工作。 127.0.0.1 连接被拒绝