From 983a108776087c1cc21d93f803df01cc7e373305 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 11 Nov 2014 15:34:08 +0000 Subject: [PATCH] Percolator: Remove `index.percolator.allow_unmapped_fields` setting. There should be no option to opt out from strict field resolution for percolator query parsing. Closes #8439 --- .../percolator/PercolatorQueriesRegistry.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index 44a939451ba..a9d3cc93ecb 100644 --- a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -68,8 +68,6 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent { - public final static String ALLOW_UNMAPPED_FIELDS = "index.percolator.allow_unmapped_fields"; - // This is a shard level service, but these below are index level service: private final IndexQueryParserService queryParserService; private final MapperService mapperService; @@ -85,7 +83,6 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent { private final RealTimePercolatorOperationListener realTimePercolatorOperationListener = new RealTimePercolatorOperationListener(); private final PercolateTypeListener percolateTypeListener = new PercolateTypeListener(); private final AtomicBoolean realTimePercolatorEnabled = new AtomicBoolean(false); - private final boolean allowUnmappedFields; private CloseableThreadLocal cache = new CloseableThreadLocal() { @Override @@ -106,7 +103,6 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent { this.indexCache = indexCache; this.indexFieldDataService = indexFieldDataService; this.shardPercolateService = shardPercolateService; - this.allowUnmappedFields = indexSettings.getAsBoolean(ALLOW_UNMAPPED_FIELDS, false); indicesLifecycle.addListener(shardLifecycleListener); mapperService.addTypeListener(percolateTypeListener); @@ -203,7 +199,16 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent { QueryParseContext context = cache.get(); try { context.reset(parser); - context.setAllowUnmappedFields(allowUnmappedFields); + // This means that fields in the query need to exist in the mapping prior to registering this query + // The reason that this is required, is that if a field doesn't exist then the query assumes defaults, which may be undesired. + // + // Even worse when fields mentioned in percolator queries do go added to map after the queries have been registered + // then the percolator queries don't work as expected any more. + // + // Query parsing can't introduce new fields in mappings (which happens when registering a percolator query), + // because field type can't be inferred from queries (like document do) so the best option here is to disallow + // the usage of unmapped fields in percolator queries to avoid unexpected behaviour + context.setAllowUnmappedFields(false); return queryParserService.parseInnerQuery(context); } catch (IOException e) { throw new QueryParsingException(queryParserService.index(), "Failed to parse", e);