*
- * see {@link ContextMappings#load(Object, Version)} for CONTEXTS
+ * see {@link ContextMappings#load(Object, org.elasticsearch.index.mapper.Mapper.TypeParser.ParserContext)} for CONTEXTS
* see {@link #parse(ParseContext)} for acceptable inputs for indexing
*
* This field type constructs completion queries that are run
@@ -144,7 +143,7 @@ public static class TypeParser implements Mapper.TypeParser {
builder.maxInputLength(Integer.parseInt(fieldNode.toString()));
iterator.remove();
} else if (Fields.CONTEXTS.match(fieldName, LoggingDeprecationHandler.INSTANCE)) {
- builder.contextMappings(ContextMappings.load(fieldNode, parserContext.indexVersionCreated()));
+ builder.contextMappings(ContextMappings.load(fieldNode, parserContext));
iterator.remove();
} else if (parseMultiField(builder, name, parserContext, fieldName, fieldNode)) {
iterator.remove();
@@ -376,7 +375,7 @@ public Builder maxInputLength(int maxInputLength) {
/**
* Add context mapping to this field
- * @param contextMappings see {@link ContextMappings#load(Object, Version)}
+ * @param contextMappings see {@link ContextMappings#load(Object, org.elasticsearch.index.mapper.Mapper.TypeParser.ParserContext)}
*/
public Builder contextMappings(ContextMappings contextMappings) {
this.contextMappings = contextMappings;
diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
index 073e7da3accb2..1df288449473a 100644
--- a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
+++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
@@ -24,11 +24,11 @@
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.ElasticsearchParseException;
-import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
+import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.StringFieldType;
@@ -79,7 +79,7 @@ public String getFieldName() {
/**
* Loads a named {@link CategoryContextMapping} instance
* from a map.
- * see {@link ContextMappings#load(Object, Version)}
+ * see {@link ContextMappings#load(Object, Mapper.TypeParser.ParserContext)}
*
* Acceptable map param: path
*/
@@ -134,7 +134,7 @@ public Set parseContext(ParseContext parseContext, XContentParser
}
@Override
- public Set parseContext(Document document) {
+ public Set parseContext(Mapper.TypeParser.ParserContext parserContext, Document document) {
Set values = null;
if (fieldName != null) {
IndexableField[] fields = document.getFields(fieldName);
diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
index 1aa82eeb2190a..f98659fe2f8c2 100644
--- a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
+++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
@@ -28,6 +28,7 @@
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.CompletionFieldMapper;
+import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.ParseContext;
import java.io.IOException;
@@ -96,7 +97,7 @@ public String name() {
/**
* Retrieves a set of context from a document at index-time.
*/
- protected abstract Set parseContext(ParseContext.Document document);
+ protected abstract Set parseContext(Mapper.TypeParser.ParserContext parserContext, ParseContext.Document document);
/**
* Prototype for the query context
diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java
index 3c0f0e80cebdb..c41f521fb71ed 100644
--- a/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java
+++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMappings.java
@@ -29,6 +29,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.CompletionFieldMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
+import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.search.suggest.completion.context.ContextMapping.Type;
@@ -54,8 +55,9 @@ public class ContextMappings implements ToXContent {
private final List> contextMappings;
private final Map> contextNameMap;
+ private final Mapper.TypeParser.ParserContext parserContext;
- public ContextMappings(List> contextMappings) {
+ public ContextMappings(List> contextMappings, Mapper.TypeParser.ParserContext parserContext) {
if (contextMappings.size() > 255) {
// we can support more, but max of 255 (1 byte) unique context types per suggest field
// seems reasonable?
@@ -66,6 +68,7 @@ public ContextMappings(List> contextMappings) {
for (ContextMapping> mapping : contextMappings) {
contextNameMap.put(mapping.name(), mapping);
}
+ this.parserContext = parserContext;
}
/**
@@ -134,7 +137,7 @@ protected Iterable contexts() {
scratch.setCharAt(0, (char) typeId);
scratch.setLength(1);
ContextMapping> mapping = contextMappings.get(typeId);
- Set contexts = new HashSet<>(mapping.parseContext(document));
+ Set contexts = new HashSet<>(mapping.parseContext(parserContext, document));
if (this.contexts.get(mapping.name()) != null) {
contexts.addAll(this.contexts.get(mapping.name()));
}
@@ -216,23 +219,24 @@ public Map> getNamedContexts(List contex
* [{"name": .., "type": .., ..}, {..}]
*
*/
- public static ContextMappings load(Object configuration, Version indexVersionCreated) throws ElasticsearchParseException {
+ public static ContextMappings load(Object configuration, Mapper.TypeParser.ParserContext parserContext)
+ throws ElasticsearchParseException {
final List> contextMappings;
if (configuration instanceof List) {
contextMappings = new ArrayList<>();
List