10
10
11
11
import org .apache .lucene .document .Document ;
12
12
import org .apache .lucene .document .Field ;
13
+ import org .apache .lucene .document .InetAddressPoint ;
13
14
import org .apache .lucene .document .NumericDocValuesField ;
14
15
import org .apache .lucene .document .SortedNumericDocValuesField ;
15
16
import org .apache .lucene .document .SortedSetDocValuesField ;
25
26
import org .apache .lucene .tests .util .TestUtil ;
26
27
import org .apache .lucene .util .BytesRef ;
27
28
import org .opensearch .common .lucene .Lucene ;
29
+ import org .opensearch .common .network .InetAddresses ;
28
30
import org .opensearch .core .xcontent .XContentBuilder ;
29
31
import org .opensearch .index .codec .composite .CompositeIndexFieldInfo ;
30
32
import org .opensearch .index .codec .composite .CompositeIndexReader ;
36
38
import org .opensearch .index .mapper .NumberFieldMapper ;
37
39
38
40
import java .io .IOException ;
41
+ import java .net .InetAddress ;
42
+ import java .util .Arrays ;
39
43
import java .util .HashMap ;
40
44
import java .util .HashSet ;
41
45
import java .util .List ;
@@ -65,12 +69,15 @@ public void testStarTreeKeywordDocValues() throws IOException {
65
69
doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
66
70
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
67
71
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
72
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
68
73
iw .addDocument (doc );
69
74
doc = new Document ();
70
75
doc .add (new StringField ("_id" , "2" , Field .Store .NO ));
71
76
doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
72
77
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
73
78
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
79
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
80
+
74
81
iw .addDocument (doc );
75
82
iw .flush ();
76
83
iw .deleteDocuments (new Term ("_id" , "2" ));
@@ -80,12 +87,14 @@ public void testStarTreeKeywordDocValues() throws IOException {
80
87
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
81
88
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
82
89
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
90
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
83
91
iw .addDocument (doc );
84
92
doc = new Document ();
85
93
doc .add (new StringField ("_id" , "4" , Field .Store .NO ));
86
94
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
87
95
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
88
96
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
97
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
89
98
iw .addDocument (doc );
90
99
iw .flush ();
91
100
iw .deleteDocuments (new Term ("_id" , "4" ));
@@ -166,6 +175,9 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
166
175
167
176
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef (keyword2Value )));
168
177
map .put (keyword1Value + "-" + keyword2Value , sndvValue + map .getOrDefault (keyword1Value + "-" + keyword2Value , 0 ));
178
+ doc .add (
179
+ new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10." + i ))))
180
+ );
169
181
iw .addDocument (doc );
170
182
documents .put (id , doc );
171
183
}
@@ -221,9 +233,7 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
221
233
SortedSetStarTreeValuesIterator k1 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator (
222
234
"keyword1"
223
235
);
224
- SortedSetStarTreeValuesIterator k2 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator (
225
- "keyword2"
226
- );
236
+ SortedSetStarTreeValuesIterator k2 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator ("ip1" );
227
237
for (StarTreeDocument starDoc : actualStarTreeDocuments ) {
228
238
String keyword1 = null ;
229
239
if (starDoc .dimensions [0 ] != null ) {
@@ -232,7 +242,11 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
232
242
233
243
String keyword2 = null ;
234
244
if (starDoc .dimensions [1 ] != null ) {
235
- keyword2 = k2 .lookupOrd (starDoc .dimensions [1 ]).utf8ToString ();
245
+ BytesRef encoded = k2 .lookupOrd (starDoc .dimensions [1 ]);
246
+ InetAddress address = InetAddressPoint .decode (
247
+ Arrays .copyOfRange (encoded .bytes , encoded .offset , encoded .offset + encoded .length )
248
+ );
249
+ keyword2 = address .toString ();
236
250
}
237
251
double metric = (double ) starDoc .metrics [0 ];
238
252
if (map .containsKey (keyword1 + "-" + keyword2 )) {
@@ -254,21 +268,28 @@ public void testStarKeywordDocValuesWithMissingDocs() throws IOException {
254
268
Document doc = new Document ();
255
269
doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
256
270
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
271
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
272
+
257
273
iw .addDocument (doc );
258
274
doc = new Document ();
259
275
doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
260
276
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
277
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
261
278
iw .addDocument (doc );
262
279
iw .forceMerge (1 );
263
280
doc = new Document ();
264
281
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
265
282
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
266
283
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
284
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
285
+
267
286
iw .addDocument (doc );
268
287
doc = new Document ();
269
288
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
270
289
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
271
290
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
291
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
292
+
272
293
iw .addDocument (doc );
273
294
iw .forceMerge (1 );
274
295
iw .close ();
@@ -340,11 +361,14 @@ public void testStarKeywordDocValuesWithMissingDocsInSegment() throws IOExceptio
340
361
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
341
362
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
342
363
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
364
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
343
365
iw .addDocument (doc );
344
366
doc = new Document ();
345
367
doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
346
368
doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
347
369
doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
370
+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
371
+
348
372
iw .addDocument (doc );
349
373
iw .forceMerge (1 );
350
374
iw .close ();
@@ -538,7 +562,7 @@ protected XContentBuilder getMapping() throws IOException {
538
562
b .field ("name" , "keyword1" );
539
563
b .endObject ();
540
564
b .startObject ();
541
- b .field ("name" , "keyword2 " );
565
+ b .field ("name" , "ip1 " );
542
566
b .endObject ();
543
567
b .endArray ();
544
568
b .startArray ("metrics" );
@@ -566,6 +590,9 @@ protected XContentBuilder getMapping() throws IOException {
566
590
b .startObject ("keyword2" );
567
591
b .field ("type" , "keyword" );
568
592
b .endObject ();
593
+ b .startObject ("ip1" );
594
+ b .field ("type" , "ip" );
595
+ b .endObject ();
569
596
b .endObject ();
570
597
});
571
598
}
0 commit comments