-
Notifications
You must be signed in to change notification settings - Fork 421
OAK-11775: improve is null queries for elasticsearch indexes
#2346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e23ad75
fde8480
748a398
2b3d74d
49e8cc8
4921474
b9f69bd
aafcff9
6d3ec16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ | |
| import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticConnection; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticPropertyDefinition; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.ElasticSemVer; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.query.async.facets.ElasticFacetProvider; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.query.inference.InferenceConfig; | ||
| import org.apache.jackrabbit.oak.plugins.index.elastic.query.inference.InferenceConstants; | ||
|
|
@@ -143,6 +144,10 @@ public class ElasticRequestHandler { | |
| private final String propertyRestrictionQuery; | ||
| private final NodeState rootState; | ||
|
|
||
| // Min/max version of ElasticSearch that supports null checks | ||
| private static final ElasticSemVer MINIMUM_NULL_CHECK_VERSION = new ElasticSemVer(1, 4, 0); | ||
| private static final ElasticSemVer MAXIMUM_NULL_CHECK_VERSION = new ElasticSemVer(1, 5, 0); | ||
|
|
||
| ElasticRequestHandler(@NotNull IndexPlan indexPlan, @NotNull FulltextIndexPlanner.PlanResult planResult, | ||
| NodeState rootState) { | ||
| this.indexPlan = indexPlan; | ||
|
|
@@ -1123,7 +1128,20 @@ private Query createQuery(String propertyName, Filter.PropertyRestriction pr, Pr | |
| final String field = elasticIndexDefinition.getElasticKeyword(propertyName); | ||
|
|
||
| if (pr.isNullRestriction()) { | ||
| return Query.of(q -> q.bool(b -> b.mustNot(m -> m.exists(e -> e.field(field))))); | ||
| // nullProps check has been added in 1.4.0. Use the old strategy when version is lower | ||
| if (elasticIndexDefinition.getMappingVersion().compareTo(MINIMUM_NULL_CHECK_VERSION) < 0) { | ||
| // check if the default mapping is >= 1.5.0 | ||
| if (ElasticIndexDefinition.MAPPING_VERSION != null && | ||
| ElasticIndexDefinition.MAPPING_VERSION.compareTo(MAXIMUM_NULL_CHECK_VERSION) >= 0) { | ||
| LOG.error("Backward compatibility for null check is not supported anymore. Query results may be incorrect. " + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should decrease logging these on each query execution., may be once every 100/1000 queries.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that but I decided to not add this complexity for the following reasons:
|
||
| "Please reindex to update the internal mapping version."); | ||
| } else { | ||
| LOG.warn("Using deprecated null check strategy for field: {}. Please reindex to update the internal mapping version. " + | ||
| "It will be removed with default index mapping version 1.5.0.", field); | ||
| return Query.of(q -> q.bool(b -> b.mustNot(mn -> mn.exists(e -> e.field(field))))); | ||
| } | ||
| } | ||
| return Query.of(q -> q.term(t -> t.field(FieldNames.NULL_PROPS).value(field))); | ||
| } | ||
| if (pr.isNotNullRestriction()) { | ||
| return Query.of(q -> q.exists(e -> e.field(field))); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.