@@ -159,6 +159,88 @@ public void testForceMergeDenseCase() throws Exception {
159159 }
160160 }
161161
162+ public void testTwoSegmentsTwoDifferentFields () throws Exception {
163+ String timestampField = "@timestamp" ;
164+ String hostnameField = "host.name" ;
165+ long timestamp = 1704067200000L ;
166+
167+ var config = getTimeSeriesIndexWriterConfig (hostnameField , timestampField );
168+ try (var dir = newDirectory (); var iw = new IndexWriter (dir , config )) {
169+ long counter1 = 0 ;
170+ long counter2 = 10_000_000 ;
171+
172+ {
173+ var d = new Document ();
174+ d .add (new SortedDocValuesField (hostnameField , new BytesRef ("host-001" )));
175+ d .add (new SortedNumericDocValuesField (timestampField , timestamp - 1 ));
176+ d .add (new NumericDocValuesField ("counter_1" , counter1 ));
177+ d .add (new SortedNumericDocValuesField ("gauge_1" , 2 ));
178+ iw .addDocument (d );
179+ iw .commit ();
180+ }
181+ {
182+ var d = new Document ();
183+ d .add (new SortedDocValuesField (hostnameField , new BytesRef ("host-001" )));
184+ d .add (new SortedNumericDocValuesField (timestampField , timestamp ));
185+ d .add (new SortedNumericDocValuesField ("counter_2" , counter2 ));
186+ d .add (new SortedNumericDocValuesField ("gauge_2" , -2 ));
187+ iw .addDocument (d );
188+ iw .commit ();
189+ }
190+
191+ iw .forceMerge (1 );
192+
193+ try (var reader = DirectoryReader .open (iw )) {
194+ assertEquals (1 , reader .leaves ().size ());
195+ assertEquals (2 , reader .maxDoc ());
196+ var leaf = reader .leaves ().get (0 ).reader ();
197+ var hostNameDV = leaf .getSortedDocValues (hostnameField );
198+ assertNotNull (hostNameDV );
199+ var timestampDV = DocValues .unwrapSingleton (leaf .getSortedNumericDocValues (timestampField ));
200+ assertNotNull (timestampDV );
201+ var counterOneDV = leaf .getNumericDocValues ("counter_1" );
202+ assertNotNull (counterOneDV );
203+ var counterTwoDV = leaf .getSortedNumericDocValues ("counter_2" );
204+ assertNotNull (counterTwoDV );
205+ var gaugeOneDV = leaf .getSortedNumericDocValues ("gauge_1" );
206+ assertNotNull (gaugeOneDV );
207+ var gaugeTwoDV = leaf .getSortedNumericDocValues ("gauge_2" );
208+ assertNotNull (gaugeTwoDV );
209+ for (int i = 0 ; i < 2 ; i ++) {
210+ assertEquals (i , hostNameDV .nextDoc ());
211+ assertEquals ("host-001" , hostNameDV .lookupOrd (hostNameDV .ordValue ()).utf8ToString ());
212+
213+ assertEquals (i , timestampDV .nextDoc ());
214+ long actualTimestamp = timestampDV .longValue ();
215+ assertTrue (actualTimestamp == timestamp || actualTimestamp == timestamp - 1 );
216+
217+ if (counterOneDV .advanceExact (i )) {
218+ long counterOneValue = counterOneDV .longValue ();
219+ assertEquals (counter1 , counterOneValue );
220+ }
221+
222+ if (counterTwoDV .advanceExact (i )) {
223+ assertEquals (1 , counterTwoDV .docValueCount ());
224+ long counterTwoValue = counterTwoDV .nextValue ();
225+ assertEquals (counter2 , counterTwoValue );
226+ }
227+
228+ if (gaugeOneDV .advanceExact (i )) {
229+ assertEquals (1 , gaugeOneDV .docValueCount ());
230+ long gaugeOneValue = gaugeOneDV .nextValue ();
231+ assertEquals (2 , gaugeOneValue );
232+ }
233+
234+ if (gaugeTwoDV .advanceExact (i )) {
235+ assertEquals (1 , gaugeTwoDV .docValueCount ());
236+ long gaugeTwoValue = gaugeTwoDV .nextValue ();
237+ assertEquals (-2 , gaugeTwoValue );
238+ }
239+ }
240+ }
241+ }
242+ }
243+
162244 public void testForceMergeSparseCase () throws Exception {
163245 String timestampField = "@timestamp" ;
164246 String hostnameField = "host.name" ;
0 commit comments