Skip to content

Commit 18732fd

Browse files
committed
OAK-11555 Elastic: support dot in property and function names
1 parent 8698705 commit 18732fd

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,18 @@ public float getSimilarityTagsBoost() {
319319
*/
320320
public String getElasticKeyword(String propertyName) {
321321
List<PropertyDefinition> propertyDefinitions = propertiesByName.get(propertyName);
322+
String field = ElasticIndexUtils.fieldName(propertyName);
322323
if (propertyDefinitions == null) {
323324
// if there are no property definitions we return the default keyword name
324325
// this can happen for properties that were not explicitly defined (eg: created with a regex)
325326
ElasticPropertyDefinition pd = getMatchingRegexPropertyDefinition(propertyName);
326-
if (pd != null) {
327-
if (pd.isFlattened()) {
328-
String fieldName = ElasticIndexUtils.fieldName(propertyName);
329-
String flattenedFieldName = FieldNames.FLATTENED_FIELD_PREFIX +
330-
ElasticIndexUtils.fieldName(pd.nodeName) + "." + fieldName;
331-
return flattenedFieldName;
332-
}
327+
if (pd != null && pd.isFlattened()) {
328+
return FieldNames.FLATTENED_FIELD_PREFIX +
329+
ElasticIndexUtils.fieldName(pd.nodeName) + "." + field;
330+
} else {
331+
return field + ".keyword";
333332
}
334-
String fieldName = ElasticIndexUtils.fieldName(propertyName);
335-
return fieldName + ".keyword";
336333
}
337-
338-
String field = ElasticIndexUtils.fieldName(propertyName);
339334
// it's ok to look at the first property since we are sure they all have the same type
340335
int type = propertyDefinitions.get(0).getType();
341336
if (isAnalyzable.apply(type) && isAnalyzed(propertyDefinitions)) {

oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,16 +649,20 @@ private ObjectBuilder<BoolQuery> inference(BoolQuery.Builder b, String propertyN
649649
}
650650

651651
private Stream<NestedQuery> dynamicScoreQueries(String text) {
652-
return elasticIndexDefinition.getDynamicBoostProperties().stream().map(pd -> NestedQuery.of(n -> n
653-
.path(ElasticIndexUtils.fieldName(pd.nodeName))
654-
.query(q -> q.functionScore(s -> s
652+
return elasticIndexDefinition.getDynamicBoostProperties().stream()
653+
.map(pd -> {
654+
String field = ElasticIndexUtils.fieldName(pd.nodeName);
655+
return NestedQuery.of(n -> n
656+
.path(field)
657+
.query(q -> q.functionScore(s -> s
655658
.boost(DYNAMIC_BOOST_WEIGHT)
656659
.query(fq -> fq.match(m -> m.field(
657-
ElasticIndexUtils.fieldName(pd.nodeName) + ".value").
660+
field + ".value").
658661
query(FieldValue.of(text))))
659662
.functions(f -> f.fieldValueFactor(fv -> fv.field(
660-
ElasticIndexUtils.fieldName(pd.nodeName) + ".boost")))))
661-
.scoreMode(ChildScoreMode.Avg))
663+
field + ".boost")))))
664+
.scoreMode(ChildScoreMode.Avg));
665+
}
662666
);
663667
}
664668

oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/facets/ElasticStatisticalFacetAsyncProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.concurrent.TimeUnit;
5050
import java.util.function.Predicate;
5151
import java.util.stream.Collectors;
52+
import java.util.stream.Stream;
5253

5354
/**
5455
* An {@link ElasticFacetProvider} extension that performs random sampling on the result set to compute facets.
@@ -75,11 +76,11 @@ public class ElasticStatisticalFacetAsyncProvider implements ElasticFacetProvide
7576

7677
this.elasticResponseHandler = elasticResponseHandler;
7778
this.isAccessible = isAccessible;
78-
Set<String> elasticFieldNames = elasticRequestHandler.facetFields().
79-
map(p -> ElasticIndexUtils.fieldName(p)).
80-
collect(Collectors.toSet());
8179
this.facetFields = elasticRequestHandler.facetFields().
8280
collect(Collectors.toSet());
81+
Set<String> elasticFieldNames = facetFields.stream().
82+
map(ElasticIndexUtils::fieldName).
83+
collect(Collectors.toSet());
8384

8485
SearchRequest searchRequest = SearchRequest.of(srb -> srb.index(indexDefinition.getIndexAlias())
8586
.trackTotalHits(thb -> thb.enabled(true))

0 commit comments

Comments
 (0)