citizenzet / elastic-query-builder
package under development
Installs: 4 186
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.3
README
<?php $client = ClientBuilder::create()->setHosts(['localhost:9200'])->build(); $query = new QueryBuilder(); $query->setIndex("_my_index"); $query->setSize(10); $query->setFrom(0); //Выбор полей $query->setSource(['title', "categories", 'features_values.Материал рамы']); //Запрос // поиск по строке $query->setQuery((new MultiMatchQuery())->setQuery("Oko Plus")->setFields(['title'])->setFuzziness(1)); //ФИльтрация $query->addFilter( (new NestedQuery())->setNestedPath("features_values") ->should() ->addQuery((new TermsQuery())->setField("features_values.Материал рамы")->setValues(["сталь"])) ->addQuery((new TermsQuery())->setField("features_values.Сиденье")->setValues(["без спинки", "со спинкой"])) ); $query->addFilter((new TermsQuery())->setField("features_values.Внутренний материал")->setValues(["байка"])); $query->addFilter((new TermsQuery())->setField("categories")->setValues([2879])); //Сортировка $query->addSorting("_id", "desc"); //Агрегации // сумма $query->addAggregation((new SumAggregation("test_sum"))->setField('count')); // максимальное значение $query->addAggregation((new MaxAggregation("max_price"))->setField('price')); // минимальное значение $query->addAggregation((new MinAggregation("max_price"))->setField('price')); //вложенные (не тестировано!!!) $query->addAggregation((new NestedAggregation("features"))->setNestedPath('features')->setAggregation( (new TermsAggregation("fffff"))->setField("features.1")->setSize(20)) ); $response = $client->search($query->build()); $r = Response::instance($response); $productCodes = $r->getSourceKeyAsArray("code"); $productIds = $r->getIds();