製品の検索を実行するために、エラスティカを使用してphpを使用したコードがあります。製品カテゴリを「off_furniture」および「home_furniture」として選択すると、elasticsearch はカテゴリが「home_category」の製品のみを返します。
これに光を当ててください。以下は私がコードを持っているものです:
$value = $_GET['prod'];
$filter_manufacturer = $_GET['man'];
$filter_price = $_GET['price'];
$cat = $_GET['cat'];
$queryString = new Elastica_Query_QueryString((string)$value);
$queryString->setDefaultOperator('OR')
->setFields(array('name'));
$category = explode("|", $cat);
$elasticaFilterBool = new Elastica_Filter_Bool();
$filter2 = new Elastica_Filter_Term();
$filter2->setTerm('prodcat', array('off_furniture','home_furniture'));
$elasticaFilterBool->addMust($filter2);
$query->setFilter($elasticaFilterBool);
// Create the search object and inject the client
$search = new Elastica_Search(new Elastica_Client());
// Configure and execute the search
$resultSet = $search->addIndex('products3')
->addType('product3')
->search($query);
foreach ($resultSet as $elasticaResult) {
$result = $elasticaResult->getData();
echo $result["name"]. "|";
echo $result["prodcat"]. "|";
echo $result["description"]. "|";
echo $result["price"]. "|";
echo $result["manufacturer"]. "|@";
}