- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我阅读了 BoolQuery 的文档根据它,这就是目的,
filter
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.
同样来自 BoolQueryBuilder 类:
/**
* Adds a query that <b>must</b> appear in the matching documents but will
* not contribute to scoring. No {@code null} value allowed.
*/
public BoolQueryBuilder filter(QueryBuilder queryBuilder) {
if (queryBuilder == null) {
throw new IllegalArgumentException("inner bool query clause cannot be null");
}
filterClauses.add(queryBuilder);
return this;
}
但是我无法理解这个。我什么时候应该使用过滤器 vs(应该或必须)
这是我正在处理的示例:
I want to filter out some records based on the following assumptions :
Fetch All
1) Records where
deleted=0
andisPrivate=true
AND
2) Records where
(isPrivate=false or [isPrivate=true and
createdBy=loggedInUser])
这是给出相同结果的 2 个查询,我想知道 filter
查询表示什么
仅使用“必须”和“应该”子句,无需过滤即可得到结果。
"query": {
"bool": {
"must": [
{
"term": {
"deleted": {
"value": "0",
"boost": 1
}
}
},
{
"match": {
"isPrivate": {
"query": true
}
}
},
{
"bool": {
"should": [
{
"term": {
"isPrivate": {
"value": "false",
"boost": 1
}
}
},
{
"bool": {
"must": [
{
"term": {
"createdBy": {
"value": "1742991596",
"boost": 1
}
}
},
{
"term": {
"isPrivate": {
"value": "true",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
]
}
}
]
}
},
使用过滤器进行查询
"query": {
"bool": {
"adjust_pure_negative": true,
"boost": 1,
"filter": [
{
"bool": {
"must": [
{
"term": {
"deleted": {
"value": "0",
"boost": 1
}
}
},
{
"match": {
"isPrivate": {
"query": true
}
}
}
],
"should": [
{
"term": {
"isPrivate": {
"value": "false",
"boost": 1
}
}
},
{
"bool": {
"must": [
{
"term": {
"createdBy": {
"value": "1742991596",
"boost": 1
}
}
},
{
"term": {
"isPrivate": {
"value": "true",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
]
}
}
最佳答案
就您而言,您绝对应该使用 bool/filter
因为您没有任何有助于评分的约束,所有约束都是是/否匹配,并且通过使用 filter
您可以从过滤器缓存中受益(使用 Must 时则不会)
因此,一定要使用过滤器选项,但稍作修改(您实际上根本不需要必须,并且您的 boolean 逻辑未正确转换为 boolean 查询):
{
"query": {
"bool": {
"minimum_should_match": 1,
"filter": [
{
"term": {
"deleted": {
"value": "0",
"boost": 1
}
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"isPrivate": {
"value": "false",
"boost": 1
}
}
},
{
"bool": {
"filter": [
{
"term": {
"createdBy": {
"value": "1742991596",
"boost": 1
}
}
},
{
"term": {
"isPrivate": {
"value": "true",
"boost": 1
}
}
}
]
}
}
]
}
}
]
}
}
}
总结一下:
应该
= OR 条件必须
= AND 条件(需要评分时)filter
= AND 条件(当不需要评分和/或当您希望从过滤器缓存中受益时)must_not
= NOT 条件关于java - ElasticSearch 中 BoolQuery 的 "filter"的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56801127/
我让 elastic.js 像这样构建动态查询: { "size": 15, "query": { "bool": { "must": [
我有以下代码,我需要在某些字段中获得非空结果,并检查其他字段中的值。 (我正在使用“RestHighLevelClient”) 但是我收到了这个错误: Caused by: Elasticsearch
我使用的是elasticsearch版本6.4.2 我成功使用 REST API 创建了 GET 查询,现在我想使用 JAVA api 执行相同的查询。 这是查询: GET _search {
我的文档中有以下字段和值,并且正在尝试获取与我的输入查询不匹配的 ids。 请查找我的 Elasticsearch 索引中的文档。 id region 1001 MEA 1002
我阅读了 BoolQuery 的文档根据它,这就是目的, filter The clause (query) must appear in matching documents. However un
我对我的代码有一些非常相似的查询。我想通过使用条件语句来缩短和清理构建通用 boolQuery 的代码。这些是我的方法: private SearchRequestBuilder createSear
我试图了解 EL 中的查询是如何工作的,说实话有很多问题。 这是我的具有属性的文档: {"statusError":null, "fileHash":"da8620bad21685c5e385fb1b
我是一名优秀的程序员,十分优秀!