Reputation: 4731
I try lot of thing for executing a simple Match value request in ElasticSearch with PHP - Elastica library (FosElasticaBundle). But nothing run. Do you have a idea for run correctly this kind of code :
$match = new Match();
$match->setFieldQuery('product.price', 2);
$match->setFieldOperator('product.price', 'AND');
$query->setQuery($match);
I'm also trying this form :
$boolQuery = new \Elastica\Query\BoolQuery();
$fieldQuery = new \Elastica\Query\Match();
$fieldQuery->setFieldQuery('age', 'I am a title string');
$fieldQuery->setFieldParam('age', 'analyzer', 'my_analyzer');
$boolQuery->addShould($fieldQuery);
$query = $boolQuery;
return $this->find($query);
No error return but nothing result. I just want this kind of request
SELECT * FROM product WHERE price = 2;
How can do that with FosElasticaBundle ?
Upvotes: 3
Views: 1003
Reputation: 491
Probably not the more convienient way of doing it but it works (you surely found a way to do it anyway) :
$price = new \Elastica\Query\Match();
$price->setField("price","2");
$product = new \Elastica\Query\Match();
$product->setField("_index","product");
$boolQuery = new \Elastica\Query\BoolQuery();
$boolQuery->addMust([$price, $product]);
$query = new \Elastica\Query($boolQuery);
Upvotes: 2