|
23 | 23 | import org.elasticsearch.common.Nullable;
|
24 | 24 | import org.elasticsearch.common.collect.Tuple;
|
25 | 25 | import org.elasticsearch.common.compress.CompressedXContent;
|
26 |
| -import org.elasticsearch.common.time.DateFormatter; |
27 | 26 | import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
28 | 27 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
29 | 28 | import org.elasticsearch.common.xcontent.XContentHelper;
|
30 | 29 | import org.elasticsearch.common.xcontent.XContentParser;
|
31 | 30 | import org.elasticsearch.common.xcontent.XContentType;
|
32 | 31 | import org.elasticsearch.index.IndexSettings;
|
33 |
| -import org.elasticsearch.index.query.QueryShardContext; |
34 |
| -import org.elasticsearch.index.similarity.SimilarityService; |
35 |
| -import org.elasticsearch.indices.mapper.MapperRegistry; |
36 |
| -import org.elasticsearch.script.ScriptService; |
| 32 | +import org.elasticsearch.index.analysis.IndexAnalyzers; |
37 | 33 |
|
38 | 34 | import java.util.HashMap;
|
39 | 35 | import java.util.Iterator;
|
40 | 36 | import java.util.Map;
|
| 37 | +import java.util.function.Function; |
41 | 38 | import java.util.function.Supplier;
|
42 | 39 |
|
43 | 40 | import static java.util.Collections.unmodifiableMap;
|
44 | 41 |
|
45 | 42 | public class DocumentMapperParser {
|
46 |
| - |
47 |
| - final MapperService mapperService; |
48 |
| - private final NamedXContentRegistry xContentRegistry; |
49 |
| - private final SimilarityService similarityService; |
50 |
| - private final Supplier<QueryShardContext> queryShardContextSupplier; |
| 43 | + private final IndexSettings indexSettings; |
| 44 | + private final IndexAnalyzers indexAnalyzers; |
| 45 | + private final Function<String, String> documentTypeResolver; |
| 46 | + private final DocumentParser documentParser; |
| 47 | + private final Function<String, Map<Class<? extends MetadataFieldMapper>, MetadataFieldMapper>> metadataMappersFunction; |
| 48 | + private final Supplier<Mapper.TypeParser.ParserContext> parserContextSupplier; |
51 | 49 | private final RootObjectMapper.TypeParser rootObjectTypeParser = new RootObjectMapper.TypeParser();
|
52 |
| - private final Version indexVersionCreated; |
53 |
| - private final Map<String, Mapper.TypeParser> typeParsers; |
54 | 50 | private final Map<String, MetadataFieldMapper.TypeParser> rootTypeParsers;
|
55 |
| - private final ScriptService scriptService; |
56 |
| - |
57 |
| - public DocumentMapperParser(IndexSettings indexSettings, |
58 |
| - MapperService mapperService, |
59 |
| - NamedXContentRegistry xContentRegistry, |
60 |
| - SimilarityService similarityService, |
61 |
| - MapperRegistry mapperRegistry, |
62 |
| - Supplier<QueryShardContext> queryShardContextSupplier, |
63 |
| - ScriptService scriptService) { |
64 |
| - this.mapperService = mapperService; |
65 |
| - this.xContentRegistry = xContentRegistry; |
66 |
| - this.similarityService = similarityService; |
67 |
| - this.queryShardContextSupplier = queryShardContextSupplier; |
68 |
| - this.scriptService = scriptService; |
69 |
| - this.typeParsers = mapperRegistry.getMapperParsers(); |
70 |
| - this.indexVersionCreated = indexSettings.getIndexVersionCreated(); |
71 |
| - this.rootTypeParsers = mapperRegistry.getMetadataMapperParsers(indexVersionCreated); |
72 |
| - } |
73 |
| - |
74 |
| - public Mapper.TypeParser.ParserContext parserContext() { |
75 |
| - return new Mapper.TypeParser.ParserContext(similarityService::getSimilarity, typeParsers::get, indexVersionCreated, |
76 |
| - queryShardContextSupplier, null, scriptService, mapperService.getIndexAnalyzers(), mapperService.getIndexSettings(), |
77 |
| - mapperService::isIdFieldDataEnabled); |
78 |
| - } |
| 51 | + private final NamedXContentRegistry xContentRegistry; |
79 | 52 |
|
80 |
| - public Mapper.TypeParser.ParserContext parserContext(DateFormatter dateFormatter) { |
81 |
| - return new Mapper.TypeParser.ParserContext(similarityService::getSimilarity, typeParsers::get, indexVersionCreated, |
82 |
| - queryShardContextSupplier, dateFormatter, scriptService, mapperService.getIndexAnalyzers(), mapperService.getIndexSettings(), |
83 |
| - mapperService::isIdFieldDataEnabled); |
| 53 | + DocumentMapperParser(IndexSettings indexSettings, |
| 54 | + IndexAnalyzers indexAnalyzers, |
| 55 | + Function<String, String> documentTypeResolver, |
| 56 | + DocumentParser documentParser, |
| 57 | + Function<String, Map<Class<? extends MetadataFieldMapper>, MetadataFieldMapper>> metadataMappersFunction, |
| 58 | + Supplier<Mapper.TypeParser.ParserContext> parserContextSupplier, |
| 59 | + Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers, |
| 60 | + NamedXContentRegistry xContentRegistry) { |
| 61 | + this.indexSettings = indexSettings; |
| 62 | + this.indexAnalyzers = indexAnalyzers; |
| 63 | + this.documentTypeResolver = documentTypeResolver; |
| 64 | + this.documentParser = documentParser; |
| 65 | + this.metadataMappersFunction = metadataMappersFunction; |
| 66 | + this.parserContextSupplier = parserContextSupplier; |
| 67 | + this.rootTypeParsers = metadataMapperParsers; |
| 68 | + this.xContentRegistry = xContentRegistry; |
84 | 69 | }
|
85 | 70 |
|
86 | 71 | public DocumentMapper parse(@Nullable String type, CompressedXContent source) throws MapperParsingException {
|
@@ -114,11 +99,11 @@ private DocumentMapper parse(String type, Map<String, Object> mapping, String de
|
114 | 99 | }
|
115 | 100 | }
|
116 | 101 |
|
117 |
| - |
118 |
| - Mapper.TypeParser.ParserContext parserContext = parserContext(); |
| 102 | + Mapper.TypeParser.ParserContext parserContext = parserContextSupplier.get(); |
119 | 103 | // parse RootObjectMapper
|
120 |
| - DocumentMapper.Builder docBuilder = new DocumentMapper.Builder( |
121 |
| - (RootObjectMapper.Builder) rootObjectTypeParser.parse(type, mapping, parserContext), mapperService); |
| 104 | + RootObjectMapper.Builder root = (RootObjectMapper.Builder) rootObjectTypeParser.parse(type, mapping, parserContext); |
| 105 | + DocumentMapper.Builder docBuilder = new DocumentMapper.Builder(root, indexSettings, indexAnalyzers, documentParser, |
| 106 | + metadataMappersFunction); |
122 | 107 | Iterator<Map.Entry<String, Object>> iterator = mapping.entrySet().iterator();
|
123 | 108 | // parse DocumentMapper
|
124 | 109 | while(iterator.hasNext()) {
|
@@ -206,7 +191,7 @@ private Tuple<String, Map<String, Object>> extractMapping(String type, Map<Strin
|
206 | 191 |
|
207 | 192 | String rootName = root.keySet().iterator().next();
|
208 | 193 | Tuple<String, Map<String, Object>> mapping;
|
209 |
| - if (type == null || type.equals(rootName) || mapperService.resolveDocumentType(type).equals(rootName)) { |
| 194 | + if (type == null || type.equals(rootName) || documentTypeResolver.apply(type).equals(rootName)) { |
210 | 195 | mapping = new Tuple<>(rootName, (Map<String, Object>) root.get(rootName));
|
211 | 196 | } else {
|
212 | 197 | mapping = new Tuple<>(type, root);
|
|
0 commit comments