org.elasticsearch.index.mapper.MapperService Java Examples
The following examples show how to use
org.elasticsearch.index.mapper.MapperService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportFieldStatsTransportAction.java From Elasticsearch with Apache License 2.0 | 7 votes |
@Override protected FieldStatsShardResponse shardOperation(FieldStatsShardRequest request) { ShardId shardId = request.shardId(); Map<String, FieldStats> fieldStats = new HashMap<>(); IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex()); MapperService mapperService = indexServices.mapperService(); IndexShard shard = indexServices.shardSafe(shardId.id()); try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) { for (String field : request.getFields()) { MappedFieldType fieldType = mapperService.fullName(field); if (fieldType != null) { IndexReader reader = searcher.reader(); Terms terms = MultiFields.getTerms(reader, field); if (terms != null) { fieldStats.put(field, fieldType.stats(terms, reader.maxDoc())); } } else { throw new IllegalArgumentException("field [" + field + "] doesn't exist"); } } } catch (IOException e) { throw ExceptionsHelper.convertToElastic(e); } return new FieldStatsShardResponse(shardId, fieldStats); }
Example #2
Source File: MetaDataIndexUpgradeService.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Checks the mappings for compatibility with the current version */ private void checkMappingsCompatibility(IndexMetaData indexMetaData) { Index index = new Index(indexMetaData.getIndex()); Settings settings = indexMetaData.getSettings(); try { SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, settings); // We cannot instantiate real analysis server at this point because the node might not have // been started yet. However, we don't really need real analyzers at this stage - so we can fake it try (AnalysisService analysisService = new FakeAnalysisService(index, settings)) { try (MapperService mapperService = new MapperService(index, settings, analysisService, similarityLookupService, scriptService, mapperRegistry, dynamicArrayFieldMapperBuilderFactoryProvider)) { for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMetaData = cursor.value; mapperService.merge(mappingMetaData.type(), mappingMetaData.source(), MapperService.MergeReason.MAPPING_RECOVERY, false); } } } } catch (Exception ex) { // Wrap the inner exception so we have the index name in the exception message throw new IllegalStateException("unable to upgrade the mappings for the index [" + indexMetaData.getIndex() + "], reason: [" + ex.getMessage() + "]", ex); } }
Example #3
Source File: PercolatorService.java From Elasticsearch with Apache License 2.0 | 6 votes |
private ParsedDocument parseFetchedDoc(PercolateContext context, BytesReference fetchedDoc, IndexService documentIndexService, String index, String type) { ParsedDocument doc = null; XContentParser parser = null; try { parser = XContentFactory.xContent(fetchedDoc).createParser(fetchedDoc); MapperService mapperService = documentIndexService.mapperService(); DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type); doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(type).flyweight(true)); if (context.highlight() != null) { doc.setSource(fetchedDoc); } } catch (Throwable e) { throw new ElasticsearchParseException("failed to parse request", e); } finally { if (parser != null) { parser.close(); } } if (doc == null) { throw new ElasticsearchParseException("No doc to percolate in the request"); } return doc; }
Example #4
Source File: SuggestUtils.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static boolean parseSuggestContext(XContentParser parser, MapperService mapperService, String fieldName, SuggestionSearchContext.SuggestionContext suggestion, ParseFieldMatcher parseFieldMatcher) throws IOException { if ("analyzer".equals(fieldName)) { String analyzerName = parser.text(); Analyzer analyzer = mapperService.analysisService().analyzer(analyzerName); if (analyzer == null) { throw new IllegalArgumentException("Analyzer [" + analyzerName + "] doesn't exists"); } suggestion.setAnalyzer(analyzer); } else if ("field".equals(fieldName)) { suggestion.setField(parser.text()); } else if ("size".equals(fieldName)) { suggestion.setSize(parser.intValue()); } else if (parseFieldMatcher.match(fieldName, Fields.SHARD_SIZE)) { suggestion.setShardSize(parser.intValue()); } else { return false; } return true; }
Example #5
Source File: InternalEngine.java From crate with Apache License 2.0 | 6 votes |
@Override public boolean hasCompleteOperationHistory(String source, MapperService mapperService, long startingSeqNo) throws IOException { if (engineConfig.getIndexSettings().isSoftDeleteEnabled()) { return getMinRetainedSeqNo() <= startingSeqNo; } else { final long currentLocalCheckpoint = getLocalCheckpointTracker().getProcessedCheckpoint(); final LocalCheckpointTracker tracker = new LocalCheckpointTracker(startingSeqNo, startingSeqNo - 1); try (Translog.Snapshot snapshot = getTranslog().newSnapshotFromMinSeqNo(startingSeqNo)) { Translog.Operation operation; while ((operation = snapshot.next()) != null) { if (operation.seqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { tracker.markSeqNoAsProcessed(operation.seqNo()); } } } return tracker.getProcessedCheckpoint() >= currentLocalCheckpoint; } }
Example #6
Source File: AutoCreateIndex.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Inject public AutoCreateIndex(Settings settings, IndexNameExpressionResolver resolver) { this.resolver = resolver; dynamicMappingDisabled = !settings.getAsBoolean(MapperService.INDEX_MAPPER_DYNAMIC_SETTING, MapperService.INDEX_MAPPER_DYNAMIC_DEFAULT); String value = settings.get("action.auto_create_index"); if (value == null || Booleans.isExplicitTrue(value)) { needToCheck = true; globallyDisabled = false; matches = null; matches2 = null; } else if (Booleans.isExplicitFalse(value)) { needToCheck = false; globallyDisabled = true; matches = null; matches2 = null; } else { needToCheck = true; globallyDisabled = false; matches = Strings.commaDelimitedListToStringArray(value); matches2 = new String[matches.length]; for (int i = 0; i < matches.length; i++) { matches2[i] = matches[i].substring(1); } } }
Example #7
Source File: ParentChildIndexFieldData.java From Elasticsearch with Apache License 2.0 | 6 votes |
public ParentChildIndexFieldData(Index index, Settings indexSettings, MappedFieldType.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache, MapperService mapperService, CircuitBreakerService breakerService) { super(index, indexSettings, fieldNames, fieldDataType, cache); this.breakerService = breakerService; if (Version.indexCreated(indexSettings).before(Version.V_2_0_0_beta1)) { parentTypes = new TreeSet<>(); for (DocumentMapper documentMapper : mapperService.docMappers(false)) { beforeCreate(documentMapper); } mapperService.addTypeListener(this); } else { ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder(); for (DocumentMapper mapper : mapperService.docMappers(false)) { ParentFieldMapper parentFieldMapper = mapper.parentFieldMapper(); if (parentFieldMapper.active()) { builder.add(parentFieldMapper.type()); } } parentTypes = builder.build(); } }
Example #8
Source File: TermSuggestParser.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public SuggestionSearchContext.SuggestionContext parse(XContentParser parser, MapperService mapperService, IndexQueryParserService queryParserService, HasContextAndHeaders headersContext) throws IOException { XContentParser.Token token; String fieldName = null; TermSuggestionContext suggestion = new TermSuggestionContext(suggester); DirectSpellcheckerSettings settings = suggestion.getDirectSpellCheckerSettings(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } else if (token.isValue()) { parseTokenValue(parser, mapperService, fieldName, suggestion, settings, queryParserService.parseFieldMatcher()); } else { throw new IllegalArgumentException("suggester[term] doesn't support field [" + fieldName + "]"); } } return suggestion; }
Example #9
Source File: LuceneQueryBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
public Context convert(WhereClause whereClause, MapperService mapperService, IndexFieldDataService indexFieldDataService, IndexCache indexCache) throws UnsupportedFeatureException { Context ctx = new Context(inputSymbolVisitor, mapperService, indexFieldDataService, indexCache); if (whereClause.noMatch()) { ctx.query = Queries.newMatchNoDocsQuery(); } else if (!whereClause.hasQuery()) { ctx.query = Queries.newMatchAllQuery(); } else { ctx.query = VISITOR.process(whereClause.query(), ctx); } if (LOGGER.isTraceEnabled()) { if (whereClause.hasQuery()) { LOGGER.trace("WHERE CLAUSE [{}] -> LUCENE QUERY [{}] ", SymbolPrinter.INSTANCE.printSimple(whereClause.query()), ctx.query); } } return ctx; }
Example #10
Source File: MatchQueryBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
public MatchQueryBuilder(MapperService mapperService, IndexCache indexCache, @Nullable BytesRef matchType, @Nullable Map options) throws IOException { this.mapperService = mapperService; this.indexCache = indexCache; if (matchType == null) { this.matchType = MultiMatchQueryBuilder.Type.BEST_FIELDS; } else { this.matchType = SUPPORTED_TYPES.get(matchType); if (this.matchType == null) { throw illegalMatchType(BytesRefs.toString(matchType)); } } this.options = OptionParser.parse(this.matchType, options); }
Example #11
Source File: FieldsVisitor.java From crate with Apache License 2.0 | 6 votes |
public void postProcess(MapperService mapperService) { final Collection<String> types = mapperService.types(); assert types.size() <= 1 : types; if (types.isEmpty() == false) { type = types.iterator().next(); } for (Map.Entry<String, List<Object>> entry : fields().entrySet()) { MappedFieldType fieldType = mapperService.fullName(entry.getKey()); if (fieldType == null) { throw new IllegalStateException("Field [" + entry.getKey() + "] exists in the index but not in mappings"); } List<Object> fieldValues = entry.getValue(); for (int i = 0; i < fieldValues.size(); i++) { fieldValues.set(i, fieldType.valueForDisplay(fieldValues.get(i))); } } }
Example #12
Source File: IndexQueryParserService.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Inject public IndexQueryParserService(Index index, IndexSettingsService indexSettingsService, IndicesQueriesRegistry indicesQueriesRegistry, ScriptService scriptService, AnalysisService analysisService, MapperService mapperService, IndexCache indexCache, IndexFieldDataService fieldDataService, BitsetFilterCache bitsetFilterCache, @Nullable SimilarityService similarityService) { super(index, indexSettingsService.getSettings()); this.indexSettingsService = indexSettingsService; this.scriptService = scriptService; this.analysisService = analysisService; this.mapperService = mapperService; this.similarityService = similarityService; this.indexCache = indexCache; this.fieldDataService = fieldDataService; this.bitsetFilterCache = bitsetFilterCache; Settings indexSettings = indexSettingsService.getSettings(); this.defaultField = indexSettings.get(DEFAULT_FIELD, AllFieldMapper.NAME); this.queryStringLenient = indexSettings.getAsBoolean(QUERY_STRING_LENIENT, false); this.parseFieldMatcher = new ParseFieldMatcher(indexSettings); this.defaultAllowUnmappedFields = indexSettings.getAsBoolean(ALLOW_UNMAPPED, true); this.indicesQueriesRegistry = indicesQueriesRegistry; }
Example #13
Source File: CodecService.java From crate with Apache License 2.0 | 6 votes |
public CodecService(@Nullable MapperService mapperService, Logger logger) { final MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder(); if (mapperService == null) { codecs.put(DEFAULT_CODEC, new Lucene84Codec()); codecs.put(BEST_COMPRESSION_CODEC, new Lucene84Codec(Mode.BEST_COMPRESSION)); } else { codecs.put(DEFAULT_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger)); codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger)); } codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault()); for (String codec : Codec.availableCodecs()) { codecs.put(codec, Codec.forName(codec)); } this.codecs = codecs.immutableMap(); }
Example #14
Source File: FetchCollector.java From Elasticsearch with Apache License 2.0 | 6 votes |
public FetchCollector(List<LuceneCollectorExpression<?>> collectorExpressions, MapperService mapperService, Engine.Searcher searcher, IndexFieldDataService indexFieldDataService, int readerId) { this.collectorExpressions = collectorExpressions; this.readerContexts = searcher.searcher().getIndexReader().leaves(); this.fieldsVisitor = new CollectorFieldsVisitor(this.collectorExpressions.size()); CollectorContext collectorContext = new CollectorContext(mapperService, indexFieldDataService, fieldsVisitor, readerId); for (LuceneCollectorExpression<?> collectorExpression : this.collectorExpressions) { collectorExpression.startCollect(collectorContext); } visitorEnabled = fieldsVisitor.required(); this.row = new InputRow(collectorExpressions); }
Example #15
Source File: MapperTestUtils.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static MapperService newMapperService(Path tempDir, Settings indexSettings, IndicesModule indicesModule) { Settings.Builder settingsBuilder = Settings.builder() .put("path.home", tempDir) .put(indexSettings); if (indexSettings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) { settingsBuilder.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); } Settings settings = settingsBuilder.build(); MapperRegistry mapperRegistry = indicesModule.getMapperRegistry(); return new MapperService(new Index("test"), settings, newAnalysisService(settings), newSimilarityLookupService(settings), null, mapperRegistry, new DynamicArrayFieldMapperBuilderFactoryProvider()); }
Example #16
Source File: ClientScopeSynchronizer.java From elasticshell with Apache License 2.0 | 6 votes |
/** * Retrieves the current indexes and types from elasticsearch * @return a set containing the indexes available in the elasticsearch cluster and their types */ protected Set<Index> getIndexes() { ClusterStateResponse response = unwrapShellNativeClient().client().admin().cluster().prepareState().setFilterBlocks(true) .setFilterRoutingTable(true).setFilterNodes(true).execute().actionGet(); Set<Index> newIndexes = new HashSet<Index>(); for (IndexMetaData indexMetaData : response.getState().metaData().indices().values()) { logger.trace("Processing index {}", indexMetaData.index()); Set<String> typeNames = Sets.filter(indexMetaData.mappings().keySet(), new Predicate<String>() { @Override public boolean apply(String s) { return !MapperService.DEFAULT_MAPPING.equals(s); } }); String[] types = typeNames.toArray(new String[typeNames.size()]); newIndexes.add(new Index(indexMetaData.index(), false, types)); for (String alias : indexMetaData.aliases().keySet()) { newIndexes.add(new Index(alias, true, types)); } } return newIndexes; }
Example #17
Source File: ArrayMapperTest.java From crate with Apache License 2.0 | 6 votes |
/** * create index with type and mapping and validate DocumentMapper serialization */ private DocumentMapper mapper(String indexName, String mapping) throws IOException { IndicesModule indicesModule = new IndicesModule(Collections.singletonList(new MapperPlugin() { @Override public Map<String, Mapper.TypeParser> getMappers() { return Collections.singletonMap(ArrayMapper.CONTENT_TYPE, new ArrayTypeParser()); } })); MapperService mapperService = MapperTestUtils.newMapperService( NamedXContentRegistry.EMPTY, createTempDir(), Settings.EMPTY, indicesModule, indexName ); DocumentMapperParser parser = mapperService.documentMapperParser(); DocumentMapper defaultMapper = parser.parse(TYPE, new CompressedXContent(mapping)); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.startObject(); defaultMapper.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); String rebuildMapping = Strings.toString(builder); return parser.parse(TYPE, new CompressedXContent(rebuildMapping)); }
Example #18
Source File: CreateAlterTableStatementAnalyzerTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testCreateTableWithTotalFieldsLimit() { BoundCreateTable analysis = analyze( "CREATE TABLE foo (id int primary key) " + "with (\"mapping.total_fields.limit\"=5000)"); assertThat(analysis.tableParameter().settings().get(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey()), is("5000")); }
Example #19
Source File: BytesBinaryDVIndexFieldData.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public IndexFieldData<?> build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore breaker final Names fieldNames = fieldType.names(); return new BytesBinaryDVIndexFieldData(index, fieldNames, fieldType.fieldDataType()); }
Example #20
Source File: TranslogRecoveryPerformer.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected TranslogRecoveryPerformer(ShardId shardId, MapperService mapperService, IndexQueryParserService queryParserService, IndexAliasesService indexAliasesService, IndexCache indexCache, ESLogger logger) { this.shardId = shardId; this.mapperService = mapperService; this.queryParserService = queryParserService; this.indexAliasesService = indexAliasesService; this.indexCache = indexCache; this.logger = logger; }
Example #21
Source File: InternalEngine.java From crate with Apache License 2.0 | 5 votes |
/** * Returns the estimated number of history operations whose seq# at least the provided seq# in this engine. */ @Override public int estimateNumberOfHistoryOperations(String source, MapperService mapperService, long startingSeqNo) throws IOException { if (engineConfig.getIndexSettings().isSoftDeleteEnabled()) { try (Translog.Snapshot snapshot = newChangesSnapshot(source, mapperService, Math.max(0, startingSeqNo), Long.MAX_VALUE, false)) { return snapshot.totalOperations(); } } else { return getTranslog().estimateTotalOperationsFromMinSeq(startingSeqNo); } }
Example #22
Source File: InternalEngine.java From crate with Apache License 2.0 | 5 votes |
/** * Creates a new history snapshot for reading operations since the provided seqno. * The returned snapshot can be retrieved from either Lucene index or translog files. */ @Override public Translog.Snapshot readHistoryOperations(String source, MapperService mapperService, long startingSeqNo) throws IOException { if (engineConfig.getIndexSettings().isSoftDeleteEnabled()) { return newChangesSnapshot(source, mapperService, Math.max(0, startingSeqNo), Long.MAX_VALUE, false); } else { return getTranslog().newSnapshotFromMinSeqNo(startingSeqNo); } }
Example #23
Source File: TranslogRecoveryPerformer.java From Elasticsearch with Apache License 2.0 | 5 votes |
private static Engine.DeleteByQuery prepareDeleteByQuery(IndexQueryParserService queryParserService, MapperService mapperService, IndexAliasesService indexAliasesService, IndexCache indexCache, BytesReference source, @Nullable String[] filteringAliases, Engine.Operation.Origin origin, String... types) { long startTime = System.nanoTime(); if (types == null) { types = Strings.EMPTY_ARRAY; } Query query; try { query = queryParserService.parseQuery(source).query(); } catch (QueryParsingException ex) { // for BWC we try to parse directly the query since pre 1.0.0.Beta2 we didn't require a top level query field if (queryParserService.getIndexCreatedVersion().onOrBefore(Version.V_1_0_0_Beta2)) { try { XContentParser parser = XContentHelper.createParser(source); ParsedQuery parse = queryParserService.parse(parser); query = parse.query(); } catch (Throwable t) { ex.addSuppressed(t); throw ex; } } else { throw ex; } } Query searchFilter = mapperService.searchFilter(types); if (searchFilter != null) { query = Queries.filtered(query, searchFilter); } Query aliasFilter = indexAliasesService.aliasFilter(filteringAliases); BitSetProducer parentFilter = mapperService.hasNested() ? indexCache.bitsetFilterCache().getBitSetProducer(Queries.newNonNestedFilter()) : null; return new Engine.DeleteByQuery(query, source, filteringAliases, aliasFilter, parentFilter, origin, startTime, types); }
Example #24
Source File: IndexMetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Sometimes, the default mapping exists and an actual mapping is not created yet (introduced), * in this case, we want to return the default mapping in case it has some default mapping definitions. * <p> * Note, once the mapping type is introduced, the default mapping is applied on the actual typed MappingMetaData, * setting its routing, timestamp, and so on if needed. */ @Nullable public MappingMetaData mappingOrDefault(String mappingType) { MappingMetaData mapping = mappings.get(mappingType); if (mapping != null) { return mapping; } return mappings.get(MapperService.DEFAULT_MAPPING); }
Example #25
Source File: MappingUpdatedAction.java From crate with Apache License 2.0 | 5 votes |
private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) { if (type.equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("_default_ mapping should not be updated"); } return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON) .setMasterNodeTimeout(timeout).setTimeout(timeout); }
Example #26
Source File: CreateAlterTableStatementAnalyzerTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testTotalFieldsLimitCanBeUsedWithAlterTable() { BoundAlterTable analysisSet = analyze( "ALTER TABLE users " + "SET (\"mapping.total_fields.limit\" = '5000')"); assertEquals("5000", analysisSet.tableParameter().settings().get(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey())); // Check if resetting total_fields results in default value BoundAlterTable analysisReset = analyze( "ALTER TABLE users " + "RESET (\"mapping.total_fields.limit\")"); assertEquals("1000", analysisReset.tableParameter().settings().get(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey())); }
Example #27
Source File: AbstractGeoPointDVIndexFieldData.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public IndexFieldData<?> build(Index index, Settings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { // Ignore breaker return new GeoPointDVIndexFieldData(index, fieldType.names(), fieldType.fieldDataType(), Version.indexCreated(indexSettings).before(Version.V_2_2_0)); }
Example #28
Source File: IndexModule.java From crate with Apache License 2.0 | 5 votes |
/** * creates a new mapper service to do administrative work like mapping updates. This *should not* be used for document parsing. * doing so will result in an exception. */ public MapperService newIndexMapperService(NamedXContentRegistry xContentRegistry, MapperRegistry mapperRegistry) throws IOException { return new MapperService( indexSettings, analysisRegistry.build(indexSettings), xContentRegistry, mapperRegistry, () -> { throw new UnsupportedOperationException("no index query shard context available"); } ); }
Example #29
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static MapperService newMapperService(Settings settings, Client client) { Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", System.getProperty("path.home")) .put("client.type", "node") .put(settings) .build(); Index index = new Index("test"); Injector parentInjector = new ModulesBuilder() .add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))) .createInjector(); AnalysisModule analysisModule = new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class)); new AnalysisBaseformPlugin(settings).onModule(analysisModule); Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), analysisModule) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); return new MapperService(new Index("test"), indexSettings, analysisService, similarityLookupService, null, mapperRegistry); }
Example #30
Source File: MappingUpdatedAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
private PutMappingRequestBuilder updateMappingRequest(String index, String type, Mapping mappingUpdate, final TimeValue timeout) { if (type.equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("_default_ mapping should not be updated"); } return client.preparePutMapping(index).setType(type).setSource(mappingUpdate.toString()) .setMasterNodeTimeout(timeout).setTimeout(timeout); }