簡體   English   中英

如何在彈性搜索+ PHP中傳遞null過濾器

[英]How to pass null filter in elastic search + PHP

我想過濾搜索結果。 我想搜索如果未指定'manuf_id'則應返回所有記錄。 以下是我的彈性搜索查詢。

$params = [
            'index' => $this->client->getIndex(),
            'type'  => $this->client->getType(),
            "from" => $from, "size" => $productPerPage,
            'body'  => [
           "query" => [
               "bool" => [
                  "must" => [
                     [
                          "multi_match" => [
                              "fields" => ["prod_name", "prod_seo_name"],
                              "type" => "phrase_prefix",
                              "query" => 'samsung'
                          ]
                     ],
                        //$conditionArr
                     [
                          "term"=> ["manuf_id"=>null]
                     ]
                  ]
               ]
            ]
            ],
       ];

以上查詢未運行。 有什么我想念的嗎? 任何幫助都會很大。

僅在必要時才可以通過此條件,例如:

$params = [
    'index' => $this->client->getIndex(),
    'type'  => $this->client->getType(),
    "from" => $from, "size" => $productPerPage,
    'body'  => [
        "query" => [
           "bool" => [
              "must" => [
                 [
                      "multi_match" => [
                          "fields" => ["prod_name", "prod_seo_name"],
                          "type" => "phrase_prefix",
                          "query" => 'samsung'
                      ]
                 ],
              ]
           ]
        ]
    ],
];
if ($manufId > 0) {
  $params['body']['query']['bool']['must'][] = [
      'term' => ['manuf_id' => $manufId],
  ];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM