if (allowIdGeneration) { if (id == null) { id(UUID.randomBase64UUID()); opType(IndexRequest.OpType.CREATE); } }
private int shardId(ClusterState clusterState, String index, String type, @Nullable String id, @Nullable String routing) { if (routing == null) { if (!useType) { return Math.abs(hash(id) % indexMetaData(clusterState, index).numberOfShards()); } else { return Math.abs(hash(type, id) % indexMetaData(clusterState, index).numberOfShards()); } } return Math.abs(hash(routing) % indexMetaData(clusterState, index).numberOfShards()); }
MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mappingOrDefault(request.type()); if (mappingMd != null && mappingMd.routing().required()) { if (request.routing() == null) { throw new RoutingMissingException(request.index(), request.type(), request.id()); } }
if (request.opType() == IndexRequest.OpType.INDEX)
Engine.Index index = indexShard.prepareIndex(sourceToParse) .version(request.version()) .versionType(request.versionType()) .origin(Engine.Operation.Origin.PRIMARY); indexShard.index(index);
public Engine.Index prepareIndex(SourceToParse source) throws ElasticSearchException { long startTime = System.nanoTime(); DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type()); ParsedDocument doc = docMapper.parse(source); return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid()), doc).startTime(startTime); }
if (currentVersion == -1) { // document does not exists, we can optimize for create if (index.docs().size() > 1) { writer.addDocuments(index.docs(), index.analyzer()); } else { writer.addDocument(index.docs().get(0), index.analyzer()); } } else { if (index.docs().size() > 1) { writer.updateDocuments(index.uid(), index.docs(), index.analyzer()); } else { writer.updateDocument(index.uid(), index.docs().get(0), index.analyzer()); } }
Translog.Location translogLocation = translog.add(new Translog.Create(create));
本文地址:http://blog.csdn.net/laigood12345/article/details/8450331
参考资料:http://www.searchtech.pro/articles/2013/02/15/1360941961206.html