【问题标题】:simple match query with Elastica QueryBuilder使用 Elastica QueryBuilder 进行简单匹配查询
【发布时间】:2017-03-13 16:54:32
【问题描述】:

我尝试了很多方法来使用 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 做到这一点?

【问题讨论】:

    标签: elasticsearch elastica foselasticabundle


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      相关资源
      最近更新 更多