Skip to content

Commit 604c407

Browse files
committed
smart search analyzer should try both fullName and then indexName, and not just indexName.
1 parent 5ac51ee commit 604c407

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ public FieldMappers smartNameFieldMappers(String smartName) {
255255
return indexName(smartName);
256256
}
257257

258+
/**
259+
* Returns smart field mappers based on a smart name. A smart name is one that can optioannly be prefixed
260+
* with a type (and then a '.'). If it is, then the {@link MapperService.SmartNameFieldMappers}
261+
* will have the doc mapper set.
262+
*
263+
* <p>It also (without the optional type prefix) try and find the {@link FieldMappers} for the specific
264+
* name. It will first try to find it based on the full name (with the dots if its a compound name). If
265+
* it is not found, will try and find it based on the indexName (which can be controlled in the mapping).
266+
*
267+
* <p>If nothing is found, returns null.
268+
*/
258269
public SmartNameFieldMappers smartName(String smartName) {
259270
int dotIndex = smartName.indexOf('.');
260271
if (dotIndex != -1) {
@@ -336,7 +347,12 @@ private SmartIndexNameSearchAnalyzer(Analyzer defaultAnalyzer) {
336347
return possibleDocMapper.mappers().searchAnalyzer().tokenStream(fieldName, reader);
337348
}
338349
}
339-
FieldMappers mappers = indexNameFieldMappers.get(fieldName);
350+
FieldMappers mappers = fullNameFieldMappers.get(fieldName);
351+
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
352+
return mappers.mapper().searchAnalyzer().tokenStream(fieldName, reader);
353+
}
354+
355+
mappers = indexNameFieldMappers.get(fieldName);
340356
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
341357
return mappers.mapper().searchAnalyzer().tokenStream(fieldName, reader);
342358
}
@@ -352,7 +368,12 @@ private SmartIndexNameSearchAnalyzer(Analyzer defaultAnalyzer) {
352368
return possibleDocMapper.mappers().searchAnalyzer().reusableTokenStream(fieldName, reader);
353369
}
354370
}
355-
FieldMappers mappers = indexNameFieldMappers.get(fieldName);
371+
FieldMappers mappers = fullNameFieldMappers.get(fieldName);
372+
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
373+
return mappers.mapper().searchAnalyzer().reusableTokenStream(fieldName, reader);
374+
}
375+
376+
mappers = indexNameFieldMappers.get(fieldName);
356377
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
357378
return mappers.mapper().searchAnalyzer().reusableTokenStream(fieldName, reader);
358379
}

0 commit comments

Comments
 (0)