gpt4 book ai didi

elasticsearch - 使用 Elastica QueryBuilder 进行简单的匹配查询

转载 作者:行者123 更新时间:2023-11-29 02:56:04 24 4
gpt4 key购买 nike

我尝试了很多事情来使用 PHP - Elastica 库 (FosElasticaBundle) 在 ElasticSearch 中执行一个简单的匹配值请求。但是没有运行。你有正确运行这种代码的想法吗:

$match = new Match();
$match->setFieldQuery('product.price', 2);
$match->setFieldOperator('product.price', 'AND');
$query->setQuery($match);

我也在尝试这种形式:

   $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);

没有错误返回但没有结果。我只想要这样的请求

SELECT * FROM product WHERE price = 2;

如何使用 FosElasticaBundle 做到这一点?

最佳答案

可能不是更方便的方法,但它有效(无论如何你肯定找到了一种方法):

$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);

关于elasticsearch - 使用 Elastica QueryBuilder 进行简单的匹配查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42769204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com