php - ElasticsearchDSL Builder如何创建不应该查询

标签 php elasticsearch dsl ongr

使用php dsl构建器,我正在尝试创建SHOULD NOT查询。使用json查询语法,您可以将MUST_NOT嵌套在SHOULD bool中以创建一个。

示例

{"bool": {"should": { "bool": {"must_not": {"match": {"thing": "thingy"}}}}}}

自从ongr文档阅读以来,尚不清楚自5.0更新版本以来如何实现相同的结果。我尝试了以下方法:
$search = new Search();
$query = new MatchQuery('thing', 'thingy');
$search->addQuery($query, BoolQuery::MUST_NOT);
$search->addPostFilter(BoolQuery::SHOULD);

但这不起作用。

最佳答案

为了嵌套 bool(boolean) 查询,您需要使用 bool(boolean) 查询:)您提供的示例可以通过以下代码片段实现:

$search = new Search();
$outerBoolQuery = new BoolQuery();
$innerBoolQuery = new BoolQuery();
$innerBoolQuery->add(new MatchQuery('thing', 'thingy'), BoolQuery::MUST_NOT);
$outerBoolQuery->add($innerBoolQuery, BoolQuery::SHOULD);

关于php - ElasticsearchDSL Builder如何创建不应该查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42424527/

相关文章:

php - 解析并显示MySQL数据到php中

php - 在 MySQL 中搜索多个单词

php - 命名空间如何在 Laravel 路由组内工作

elasticsearch - 配置 Elasticsearch 索引

ElasticSearch Phrase Suggester 不返回任何结果

haskell - Haskell quasiquotation 如何用于替换 Haskell 级别的 token ?

dsl - 哪个更适合 UI 或 DSL?

php - 在ajax post mysql上形成序列化非法字符串偏移量 ''

elasticsearch - 通过日汇总,两个属性的总和进行 Elasticsearch

ruby-on-rails - 为什么 Ruby on Rails 被称为领域特定语言?