mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 22:36:20 +00:00
rename type method on MapperService to the more descriptive documentMapperWithAutoCreate
This commit is contained in:
parent
e0b2b4b4a6
commit
f869951364
4
.idea/modules/plugin-cloud-aws.iml
generated
4
.idea/modules/plugin-cloud-aws.iml
generated
@ -20,7 +20,9 @@
|
||||
<root url="jar://$GRADLE_REPOSITORY$/com.amazonaws/aws-java-sdk/jars/aws-java-sdk-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/opt/aws-java-sdk/1.1.1/lib/aws-java-sdk-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module" module-name="test-testng" scope="TEST" />
|
||||
|
@ -76,7 +76,7 @@ public class TransportGetAction extends TransportShardSingleOperationAction<GetR
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.index());
|
||||
IndexShard indexShard = indexService.shardSafe(shardId);
|
||||
|
||||
DocumentMapper docMapper = indexService.mapperService().type(request.type());
|
||||
DocumentMapper docMapper = indexService.mapperService().documentMapper(request.type());
|
||||
if (docMapper == null) {
|
||||
throw new DocumentMapperNotFoundException("No mapper found for type [" + request.type() + "]");
|
||||
}
|
||||
|
@ -125,25 +125,6 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||
return mappers.values().iterator();
|
||||
}
|
||||
|
||||
public DocumentMapper type(String type) {
|
||||
DocumentMapper mapper = mappers.get(type);
|
||||
if (mapper != null) {
|
||||
return mapper;
|
||||
}
|
||||
if (!dynamic) {
|
||||
return null;
|
||||
}
|
||||
// go ahead and dynamically create it
|
||||
synchronized (mutex) {
|
||||
mapper = mappers.get(type);
|
||||
if (mapper != null) {
|
||||
return mapper;
|
||||
}
|
||||
add(type, null);
|
||||
return mappers.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
public DocumentMapperParser documentMapperParser() {
|
||||
return this.documentParser;
|
||||
}
|
||||
@ -231,6 +212,25 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||
return mappers.get(type);
|
||||
}
|
||||
|
||||
public DocumentMapper documentMapperWithAutoCreate(String type) {
|
||||
DocumentMapper mapper = mappers.get(type);
|
||||
if (mapper != null) {
|
||||
return mapper;
|
||||
}
|
||||
if (!dynamic) {
|
||||
return null;
|
||||
}
|
||||
// go ahead and dynamically create it
|
||||
synchronized (mutex) {
|
||||
mapper = mappers.get(type);
|
||||
if (mapper != null) {
|
||||
return mapper;
|
||||
}
|
||||
add(type, null);
|
||||
return mappers.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A filter to filter based on several types.
|
||||
*/
|
||||
|
@ -40,7 +40,10 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadSafe;
|
||||
import org.elasticsearch.index.cache.IndexCache;
|
||||
import org.elasticsearch.index.engine.*;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.SourceToParse;
|
||||
import org.elasticsearch.index.query.IndexQueryParser;
|
||||
import org.elasticsearch.index.query.IndexQueryParserMissingException;
|
||||
import org.elasticsearch.index.query.IndexQueryParserService;
|
||||
@ -208,10 +211,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||
}
|
||||
|
||||
@Override public Engine.Create prepareCreate(SourceToParse source) throws ElasticSearchException {
|
||||
DocumentMapper docMapper = mapperService.type(source.type());
|
||||
if (docMapper == null) {
|
||||
throw new DocumentMapperNotFoundException("No mapper found for type [" + source.type() + "]");
|
||||
}
|
||||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type());
|
||||
ParsedDocument doc = docMapper.parse(source);
|
||||
return new Engine.Create(doc);
|
||||
}
|
||||
@ -226,10 +226,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||
}
|
||||
|
||||
@Override public Engine.Index prepareIndex(SourceToParse source) throws ElasticSearchException {
|
||||
DocumentMapper docMapper = mapperService.type(source.type());
|
||||
if (docMapper == null) {
|
||||
throw new DocumentMapperNotFoundException("No mapper found for type [" + source.type() + "]");
|
||||
}
|
||||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type());
|
||||
ParsedDocument doc = docMapper.parse(source);
|
||||
return new Engine.Index(docMapper.uidMapper().term(doc.uid()), doc);
|
||||
}
|
||||
@ -244,10 +241,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||
}
|
||||
|
||||
@Override public Engine.Delete prepareDelete(String type, String id) throws ElasticSearchException {
|
||||
DocumentMapper docMapper = mapperService.type(type);
|
||||
if (docMapper == null) {
|
||||
throw new DocumentMapperNotFoundException("No mapper found for type [" + type + "]");
|
||||
}
|
||||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(type);
|
||||
return new Engine.Delete(docMapper.uidMapper().term(type, id));
|
||||
}
|
||||
|
||||
@ -299,10 +293,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||
|
||||
@Override public byte[] get(String type, String id) throws ElasticSearchException {
|
||||
readAllowed();
|
||||
DocumentMapper docMapper = mapperService.type(type);
|
||||
if (docMapper == null) {
|
||||
throw new DocumentMapperNotFoundException("No mapper found for type [" + type + "]");
|
||||
}
|
||||
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(type);
|
||||
Engine.Searcher searcher = engine.searcher();
|
||||
try {
|
||||
int docId = Lucene.docId(searcher.reader(), docMapper.uidMapper().term(type, id));
|
||||
|
@ -276,6 +276,9 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
||||
logger.debug("[{}] adding mapping [{}], source [{}]", index, mappingType, mappingSource.string());
|
||||
}
|
||||
mapperService.add(mappingType, mappingSource.string());
|
||||
// if (!mapperService.documentMapper(mappingType).mappingSource().equals(mappingSource)) {
|
||||
// logger.warn("[{}] parsed mapping [{}], and got different sources\noriginal:\n{}\nparsed:\n{}", mappingType, mappingSource, mapperService.documentMapper(mappingType).mappingSource());
|
||||
// }
|
||||
nodeMappingCreatedAction.nodeMappingCreated(new NodeMappingCreatedAction.NodeMappingCreatedResponse(index, mappingType, event.state().nodes().localNodeId()));
|
||||
} else {
|
||||
DocumentMapper existingMapper = mapperService.documentMapper(mappingType);
|
||||
@ -285,6 +288,9 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
|
||||
logger.debug("[{}] updating mapping [{}], source [{}]", index, mappingType, mappingSource.string());
|
||||
}
|
||||
mapperService.add(mappingType, mappingSource.string());
|
||||
// if (!mapperService.documentMapper(mappingType).mappingSource().equals(mappingSource)) {
|
||||
// logger.warn("[{}] parsed mapping [{}], and got different sources\noriginal:\n{}\nparsed:\n{}", mappingType, mappingSource, mapperService.documentMapper(mappingType).mappingSource());
|
||||
// }
|
||||
nodeMappingCreatedAction.nodeMappingCreated(new NodeMappingCreatedAction.NodeMappingCreatedResponse(index, mappingType, event.state().nodes().localNodeId()));
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class FetchPhase implements SearchPhase {
|
||||
Document doc = loadDocument(context, fieldSelector, docId);
|
||||
Uid uid = extractUid(context, doc);
|
||||
|
||||
DocumentMapper documentMapper = context.mapperService().type(uid.type());
|
||||
DocumentMapper documentMapper = context.mapperService().documentMapper(uid.type());
|
||||
|
||||
byte[] source = extractSource(doc, documentMapper);
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class HighlightPhase implements SearchHitPhase {
|
||||
|
||||
@Override public void execute(SearchContext context, InternalSearchHit hit, Uid uid, IndexReader reader, int docId) throws ElasticSearchException {
|
||||
try {
|
||||
DocumentMapper documentMapper = context.mapperService().type(hit.type());
|
||||
DocumentMapper documentMapper = context.mapperService().documentMapper(hit.type());
|
||||
|
||||
Map<String, HighlightField> highlightFields = newHashMap();
|
||||
for (SearchContextHighlight.Field field : context.highlight().fields()) {
|
||||
|
@ -75,7 +75,7 @@ public class DefaultSourceMappingTests {
|
||||
MapperService mapperService = MapperTests.newMapperService();
|
||||
mapperService.add(MapperService.DEFAULT_MAPPING, defaultMapping);
|
||||
|
||||
XContentDocumentMapper mapper = (XContentDocumentMapper) mapperService.type("my_type");
|
||||
XContentDocumentMapper mapper = (XContentDocumentMapper) mapperService.documentMapperWithAutoCreate("my_type");
|
||||
assertThat(mapper.type(), equalTo("my_type"));
|
||||
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class DefaultSourceMappingTests {
|
||||
.endObject().endObject().string();
|
||||
mapperService.add("my_type", mapping);
|
||||
|
||||
XContentDocumentMapper mapper = (XContentDocumentMapper) mapperService.type("my_type");
|
||||
XContentDocumentMapper mapper = (XContentDocumentMapper) mapperService.documentMapper("my_type");
|
||||
assertThat(mapper.type(), equalTo("my_type"));
|
||||
assertThat(mapper.sourceMapper().enabled(), equalTo(true));
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class SimpleIndexQueryParserTests {
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/mapping.json");
|
||||
injector.getInstance(MapperService.class).add("person", mapping);
|
||||
injector.getInstance(MapperService.class).type("person").parse(copyToBytesFromClasspath("/org/elasticsearch/index/query/xcontent/data.json"));
|
||||
injector.getInstance(MapperService.class).documentMapper("person").parse(copyToBytesFromClasspath("/org/elasticsearch/index/query/xcontent/data.json"));
|
||||
this.queryParser = injector.getInstance(IndexQueryParserService.class);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user