2016-07-24 46 views
0

我正在使用彈性搜索2.2.0,並且我是新的。我想使用兩個過濾器搜索結果,但它顯示我致命錯誤:查詢不支持多個字段。多項術語過濾器不適用於彈性搜索

兩個濾波器:

plocation: china 
pcategoryid: 0,20,21 

這裏是我的代碼:

$search = 'Doors'; 
$limit = 6; 
$params = [ 
    'index' => 'product', 
    'body' => [ 
     'query' => [ 
      "bool" => [ 
       "should" => [ 
        'multi_match' => [ 
         "fields" => [ 
          "pname", 
          "pmodel", 
          "pcategoryname", 
          "pmetakeyword" 
         ], 
         "query" => $search, 
         "type" => "phrase", 
         "boost" => 10 
        ], 
        'multi_match' => [ 
         "fields" => [ 
          "pname", 
          "pmodel", 
          "pcategoryname", 
          "pmetakeyword" 
         ], 
         "query" => $search, 
         "type" => "most_fields", 
         "fuzziness" => "1", 
         "boost" => 0 
        ] 
       ] 
      ], 
     ], 

     "filter" => [ 
      "bool" => [ 
       "must" => [ 
        "term" => [ 
         "ptypeid" => 1 
        ] 
       ], 
       "should" => [ 
        "term" => [ 
         "psearchstatus" => 1 
        ] 
       ], 
       "filter" => [ 
        "terms" => [ 
         "plocation" => ['china'], "pcategoryid" => [0,20,21] 
        ] 
       ] 
      ], 
     ], 
     "from" => ($page - 1) * $limit, 
     "size" => $limit 
    ], 
]; 
$client = Elasticsearch\ClientBuilder::create()->build(); 
$response = $client->search($params); 
$results = $response['hits']['hits']; 

有另一種方式去了解什麼,我試圖做的,還是我在正確的軌道上?

+0

也請提供您的索引/類型的結構 – Dekel

回答

-2

問題是您嘗試應用的terms filter。就像上面的term過濾器一樣,它只接受一個字段,但只有一個值的數組。

"terms" => [ 
    "plocation" => ['china'], "pcategoryid" => [0,20,21] 
] 

應該

"terms" => [ 
    "plocation" => ['china'] 
], 
"terms" => [ 
    "pcategoryid" => [0,20,21] 
] 
+0

不知道爲什麼,這是偷渡式downvoted,但是這是問題。 – pickypg