Java Code Examples for org.elasticsearch.index.IndexService#mapperService()
The following examples show how to use
org.elasticsearch.index.IndexService#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: 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 3
Source File: NodeFetchOperation.java From crate with Apache License 2.0 | 6 votes |
FetchCollector createCollector(int readerId, RamAccounting ramAccounting) { IndexService indexService = fetchTask.indexService(readerId); var mapperService = indexService.mapperService(); LuceneReferenceResolver resolver = new LuceneReferenceResolver( fetchTask.indexService(readerId).index().getName(), mapperService::fullName, fetchTask.table(readerId).partitionedByColumns() ); ArrayList<LuceneCollectorExpression<?>> exprs = new ArrayList<>(refs.size()); for (Reference reference : refs) { exprs.add(resolver.getImplementation(reference)); } return new FetchCollector( exprs, streamers, fetchTask.searcher(readerId), ramAccounting, readerId ); }
Example 4
Source File: NodeFetchOperation.java From Elasticsearch with Apache License 2.0 | 5 votes |
public FetchCollector createCollector(int readerId) { IndexService indexService = fetchContext.indexService(readerId); LuceneReferenceResolver resolver = new LuceneReferenceResolver(indexService.mapperService()); ArrayList<LuceneCollectorExpression<?>> exprs = new ArrayList<>(refs.size()); for (Reference reference : refs) { exprs.add(resolver.getImplementation(reference.info())); } return new FetchCollector(exprs, indexService.mapperService(), fetchContext.searcher(readerId), indexService.fieldData(), readerId ); }
Example 5
Source File: IndicesClusterStateService.java From Elasticsearch with Apache License 2.0 | 4 votes |
private void applyMappings(ClusterChangedEvent event) { // go over and update mappings for (IndexMetaData indexMetaData : event.state().metaData()) { if (!indicesService.hasIndex(indexMetaData.getIndex())) { // we only create / update here continue; } List<String> typesToRefresh = new ArrayList<>(); String index = indexMetaData.getIndex(); IndexService indexService = indicesService.indexService(index); if (indexService == null) { // got deleted on us, ignore (closing the node) return; } try { MapperService mapperService = indexService.mapperService(); // go over and add the relevant mappings (or update them) for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) { MappingMetaData mappingMd = cursor.value; String mappingType = mappingMd.type(); CompressedXContent mappingSource = mappingMd.source(); if (processMapping(index, mapperService, mappingType, mappingSource, mappingMd.mappingVersion())) { typesToRefresh.add(mappingType); } } if (typesToRefresh.isEmpty() == false && sendRefreshMapping) { nodeMappingRefreshAction.nodeMappingRefresh(event.state(), new NodeMappingRefreshAction.NodeMappingRefreshRequest(index, indexMetaData.getIndexUUID(), typesToRefresh.toArray(new String[typesToRefresh.size()]), event.state().nodes().localNodeId()) ); } } catch (Throwable t) { // if we failed the mappings anywhere, we need to fail the shards for this index, note, we safeguard // by creating the processing the mappings on the master, or on the node the mapping was introduced on, // so this failure typically means wrong node level configuration or something similar for (IndexShard indexShard : indexService) { ShardRouting shardRouting = indexShard.routingEntry(); failAndRemoveShard(shardRouting, indexService, true, "failed to update mappings", t); } } } }