@@ -62,6 +62,19 @@ public final class IngestDocument {
62
62
63
63
// Contains all pipelines that have been executed for this document
64
64
private final Set <String > executedPipelines = new LinkedHashSet <>();
65
+
66
+ /**
67
+ * An ordered set of the values of the _index that have been used for this document.
68
+ * <p>
69
+ * IMPORTANT: This is only updated after a top-level pipeline has run (see {@code IngestService#executePipelines(...)}).
70
+ * <p>
71
+ * For example, if a processor changes the _index for a document from 'foo' to 'bar',
72
+ * and then another processor changes the value back to 'foo', then the overall effect
73
+ * of the pipeline was that the _index value did not change and so only 'foo' would appear
74
+ * in the index history.
75
+ */
76
+ private Set <String > indexHistory = new LinkedHashSet <>();
77
+
65
78
private boolean doNoSelfReferencesCheck = false ;
66
79
private boolean reroute = false ;
67
80
@@ -70,21 +83,27 @@ public IngestDocument(String index, String id, long version, String routing, Ver
70
83
this .ingestMetadata = new HashMap <>();
71
84
this .ingestMetadata .put (TIMESTAMP , ctxMap .getMetadata ().getNow ());
72
85
this .templateModel = initializeTemplateModel ();
86
+
87
+ // initialize the index history by putting the current index into it
88
+ this .indexHistory .add (index );
73
89
}
74
90
91
+ // note: these rest of these constructors deal with the data-centric view of the IngestDocument, not the execution-centric view.
92
+ // For example, the copy constructor doesn't populate the `executedPipelines` or `indexHistory` (as well as some other fields),
93
+ // because those fields are execution-centric.
94
+
75
95
/**
76
- * Copy constructor that creates a new {@link IngestDocument} which has exactly the same properties as the one provided as argument
96
+ * Copy constructor that creates a new {@link IngestDocument} which has exactly the same properties as the one provided.
77
97
*/
78
98
public IngestDocument (IngestDocument other ) {
79
99
this (
80
100
new IngestCtxMap (deepCopyMap (other .ctxMap .getSource ()), other .ctxMap .getMetadata ().clone ()),
81
101
deepCopyMap (other .ingestMetadata )
82
102
);
83
- this .reroute = other .reroute ;
84
103
}
85
104
86
105
/**
87
- * Constructor to create an IngestDocument from its constituent maps. The maps are shallow copied.
106
+ * Constructor to create an IngestDocument from its constituent maps. The maps are shallow copied.
88
107
*/
89
108
public IngestDocument (Map <String , Object > sourceAndMetadata , Map <String , Object > ingestMetadata ) {
90
109
Map <String , Object > source ;
@@ -107,7 +126,7 @@ public IngestDocument(Map<String, Object> sourceAndMetadata, Map<String, Object>
107
126
}
108
127
109
128
/**
110
- * Constructor to create an IngestDocument from its constituent maps
129
+ * Constructor to create an IngestDocument from its constituent maps.
111
130
*/
112
131
IngestDocument (IngestCtxMap ctxMap , Map <String , Object > ingestMetadata ) {
113
132
this .ctxMap = Objects .requireNonNull (ctxMap );
@@ -841,6 +860,24 @@ List<String> getPipelineStack() {
841
860
return pipelineStack ;
842
861
}
843
862
863
+ /**
864
+ * Adds an index to the index history for this document, returning true if the index
865
+ * was added to the index history (i.e. if it wasn't already in the index history).
866
+ *
867
+ * @param index the index to potentially add to the index history
868
+ * @return true if the index history did not already contain the index in question
869
+ */
870
+ public boolean updateIndexHistory (String index ) {
871
+ return indexHistory .add (index );
872
+ }
873
+
874
+ /**
875
+ * @return an unmodifiable view of the document's index history
876
+ */
877
+ public Set <String > getIndexHistory () {
878
+ return Collections .unmodifiableSet (indexHistory );
879
+ }
880
+
844
881
/**
845
882
* @return Whether a self referencing check should be performed
846
883
*/
@@ -990,7 +1027,7 @@ static ResolveResult error(String errorMessage) {
990
1027
/**
991
1028
* Provides a shallowly read-only, very limited, map-like view of two maps. The only methods that are implemented are
992
1029
* {@link Map#get(Object)} and {@link Map#containsKey(Object)}, everything else throws UnsupportedOperationException.
993
- *
1030
+ * <p>
994
1031
* The overrides map has higher priority than the primary map -- values in that map under some key will take priority over values
995
1032
* in the primary map under the same key.
996
1033
*
0 commit comments