Java Code Examples for org.elasticsearch.index.engine.Engine#Index
The following examples show how to use
org.elasticsearch.index.engine.Engine#Index .
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: RecoverySourceHandlerTests.java From crate with Apache License 2.0 | 6 votes |
private Engine.Index getIndex(final String id) { final String type = "test"; final ParseContext.Document document = new ParseContext.Document(); document.add(new TextField("test", "test", Field.Store.YES)); final Field idField = new Field("_id", Uid.encodeId(id), IdFieldMapper.Defaults.FIELD_TYPE); final Field versionField = new NumericDocValuesField("_version", Versions.MATCH_ANY); final SeqNoFieldMapper.SequenceIDFields seqID = SeqNoFieldMapper.SequenceIDFields.emptySeqID(); document.add(idField); document.add(versionField); document.add(seqID.seqNo); document.add(seqID.seqNoDocValue); document.add(seqID.primaryTerm); final BytesReference source = new BytesArray(new byte[] { 1 }); final ParsedDocument doc = new ParsedDocument(versionField, seqID, id, type, List.of(document), source, null); return new Engine.Index( new Term("_id", Uid.encodeId(doc.id())), doc, UNASSIGNED_SEQ_NO, 0, Versions.MATCH_ANY, VersionType.INTERNAL, PRIMARY, System.nanoTime(), -1, false, UNASSIGNED_SEQ_NO, 0); }
Example 2
Source File: IndexShard.java From crate with Apache License 2.0 | 6 votes |
public static Engine.Index prepareIndex(DocumentMapper docMapper, SourceToParse source, long seqNo, long primaryTerm, long version, VersionType versionType, Engine.Operation.Origin origin, long autoGeneratedIdTimestamp, boolean isRetry, long ifSeqNo, long ifPrimaryTerm) { long startTime = System.nanoTime(); ParsedDocument doc = docMapper.parse(source); Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(doc.id())); return new Engine.Index(uid, doc, seqNo, primaryTerm, version, versionType, origin, startTime, autoGeneratedIdTimestamp, isRetry, ifSeqNo, ifPrimaryTerm); }
Example 3
Source File: IndexShard.java From Elasticsearch with Apache License 2.0 | 6 votes |
private void reindex(QueryFetchSearchResult hits, String index, String type) { logger.debug("Reindex: [index:{}, type:{}]", index, type); if (state == IndexShardState.STARTED) { for (InternalSearchHit hit : hits.fetchResult().hits().internalHits()) { // no difference between PRIMARY and REPLICA SourceToParse source = SourceToParse.source(SourceToParse.Origin.REPLICA, hit.sourceRef()) .index(index).type(type).id(hit.id()); if (hit.field(ParentFieldMapper.NAME).getValue() != null) { source.parent((String) hit.field(ParentFieldMapper.NAME).getValue()); } if (hit.field(TimestampFieldMapper.NAME).getValue() != null) { source.timestamp((long) hit.field(TimestampFieldMapper.NAME).getValue()); } long version = 0; if (hit.field(VersionFieldMapper.NAME).getValue() != null) { version = (long) hit.field(VersionFieldMapper.NAME).getValue(); } Engine.Index indexOp = prepareIndex(docMapper(source.type()), source, version, VersionType.EXTERNAL_GTE, Engine.Operation.Origin.RECOVERY, state != IndexShardState.STARTED); indexOp.setReindex(true); index(indexOp); } } }
Example 4
Source File: PercolatorQueriesRegistry.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void postIndexUnderLock(Engine.Index index) { // add the query under a doc lock if (PercolatorService.TYPE_NAME.equals(index.type())) { addPercolateQuery(index.id(), index.source()); } }
Example 5
Source File: WebSocketIndexListener.java From es-change-feed-plugin with Apache License 2.0 | 5 votes |
@Override public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) { ChangeEvent change=new ChangeEvent( shardId.getIndex().getName(), index.type(), index.id(), new DateTime(), result.isCreated() ? ChangeEvent.Operation.CREATE : ChangeEvent.Operation.INDEX, result.getVersion(), index.source() ); addChange(change); }
Example 6
Source File: Translog.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Index(Engine.Index index) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.parent = index.parent(); this.version = index.version(); this.timestamp = index.timestamp(); this.ttl = index.ttl(); this.versionType = index.versionType(); }
Example 7
Source File: IndexShard.java From Elasticsearch with Apache License 2.0 | 5 votes |
static Engine.Index prepareIndex(DocumentMapperForType docMapper, SourceToParse source, long version, VersionType versionType, Engine .Operation.Origin origin, boolean canHaveDuplicates) { long startTime = System.nanoTime(); ParsedDocument doc = docMapper.getDocumentMapper().parse(source); if (docMapper.getMapping() != null) { doc.addDynamicMappingsUpdate(docMapper.getMapping()); } return new Engine.Index(docMapper.getDocumentMapper().uidMapper().term(doc.uid().stringValue()), doc, version, versionType, origin, startTime, canHaveDuplicates); }
Example 8
Source File: IndexShard.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Engine.Index prepareIndexOnReplica(SourceToParse source, long version, VersionType versionType, boolean canHaveDuplicates) { try { return prepareIndex(docMapper(source.type()), source, version, versionType, Engine.Operation.Origin.REPLICA, state != IndexShardState.STARTED || canHaveDuplicates); } catch (Throwable t) { verifyNotClosed(t); throw t; } }
Example 9
Source File: Translog.java From crate with Apache License 2.0 | 5 votes |
public Index(Engine.Index index, Engine.IndexResult indexResult) { this.id = index.id(); this.type = index.type(); this.source = index.source(); this.routing = index.routing(); this.seqNo = indexResult.getSeqNo(); this.primaryTerm = index.primaryTerm(); this.version = indexResult.getVersion(); this.autoGeneratedIdTimestamp = index.getAutoGeneratedIdTimestamp(); }
Example 10
Source File: RecoverySourceHandlerTests.java From crate with Apache License 2.0 | 5 votes |
@Test public void testSendSnapshotStopOnError() throws Exception { final int fileChunkSizeInBytes = between(1, 10 * 1024); final StartRecoveryRequest request = getStartRecoveryRequest(); final IndexShard shard = mock(IndexShard.class); when(shard.state()).thenReturn(IndexShardState.STARTED); final List<Translog.Operation> ops = new ArrayList<>(); for (int numOps = between(1, 256), i = 0; i < numOps; i++) { final Engine.Index index = getIndex(Integer.toString(i)); ops.add(new Translog.Index(index, new Engine.IndexResult(1, 1, i, true))); } final AtomicBoolean wasFailed = new AtomicBoolean(); RecoveryTargetHandler recoveryTarget = new TestRecoveryTargetHandler() { @Override public void indexTranslogOperations(List<Translog.Operation> operations, int totalTranslogOps, long timestamp, long msu, ActionListener<Long> listener) { if (randomBoolean()) { maybeExecuteAsync(() -> listener.onResponse(SequenceNumbers.NO_OPS_PERFORMED)); } else { maybeExecuteAsync(() -> listener.onFailure(new RuntimeException("test - failed to index"))); wasFailed.set(true); } } }; RecoverySourceHandler handler = new RecoverySourceHandler(shard, recoveryTarget, request, fileChunkSizeInBytes, between(1, 10)); PlainActionFuture<RecoverySourceHandler.SendSnapshotResult> future = new PlainActionFuture<>(); final long startingSeqNo = randomLongBetween(0, ops.size() - 1L); final long endingSeqNo = randomLongBetween(startingSeqNo, ops.size() - 1L); handler.phase2(startingSeqNo, startingSeqNo, endingSeqNo, newTranslogSnapshot(ops, Collections.emptyList()), randomNonNegativeLong(), randomNonNegativeLong(), future); if (wasFailed.get()) { assertThat(expectThrows(RuntimeException.class, future::actionGet).getMessage(), equalTo("test - failed to index")); } }
Example 11
Source File: ShardIndexingService.java From Elasticsearch with Apache License 2.0 | 5 votes |
public void postIndexUnderLock(Engine.Index index) { for (IndexingOperationListener listener : listeners) { try { listener.postIndexUnderLock(index); } catch (Exception e) { logger.warn("postIndexUnderLock listener [{}] failed", e, listener); } } }
Example 12
Source File: ShardIndexingService.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Engine.Index preIndex(Engine.Index index) { totalStats.indexCurrent.inc(); typeStats(index.type()).indexCurrent.inc(); for (IndexingOperationListener listener : listeners) { index = listener.preIndex(index); } return index; }
Example 13
Source File: PercolatorQueriesRegistry.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Engine.Index preIndex(Engine.Index index) { // validate the query here, before we index if (PercolatorService.TYPE_NAME.equals(index.type())) { parsePercolatorDocument(index.id(), index.source()); } return index; }
Example 14
Source File: IndexingOperationListener.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Called before the indexing occurs. */ public Engine.Index preIndex(Engine.Index index) { return index; }
Example 15
Source File: IndexingSlowLog.java From Elasticsearch with Apache License 2.0 | 4 votes |
void postIndex(Engine.Index index, long tookInNanos) { postIndexing(index.parsedDoc(), tookInNanos); }
Example 16
Source File: IndexingOperationListener.java From crate with Apache License 2.0 | 4 votes |
/** * Called before the indexing occurs. */ default Engine.Index preIndex(ShardId shardId, Engine.Index operation) { return operation; }
Example 17
Source File: IndexVersionShardService.java From siren-join with GNU Affero General Public License v3.0 | 4 votes |
@Override public void postIndexUnderLock(Engine.Index index) { version.incrementAndGet(); }
Example 18
Source File: IndexingOperationListener.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Called after the indexing operation occurred. */ public void postIndex(Engine.Index index) { }
Example 19
Source File: IndexingOperationListener.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Called after the indexing operation occurred with exception. */ public void postIndex(Engine.Index index, Throwable ex) { }
Example 20
Source File: IndexingOperationListener.java From crate with Apache License 2.0 | 2 votes |
/** * Called after the indexing operation occurred with engine level exception. * See {@link #postIndex(ShardId, Engine.Index, Engine.IndexResult)} for document * related failures */ default void postIndex(ShardId shardId, Engine.Index index, Exception ex) { }