1010
1111import org .apache .lucene .document .Document ;
1212import org .apache .lucene .document .Field ;
13+ import org .apache .lucene .document .InetAddressPoint ;
1314import org .apache .lucene .document .NumericDocValuesField ;
1415import org .apache .lucene .document .SortedNumericDocValuesField ;
1516import org .apache .lucene .document .SortedSetDocValuesField ;
2526import org .apache .lucene .tests .util .TestUtil ;
2627import org .apache .lucene .util .BytesRef ;
2728import org .opensearch .common .lucene .Lucene ;
29+ import org .opensearch .common .network .InetAddresses ;
2830import org .opensearch .core .xcontent .XContentBuilder ;
2931import org .opensearch .index .codec .composite .CompositeIndexFieldInfo ;
3032import org .opensearch .index .codec .composite .CompositeIndexReader ;
3638import org .opensearch .index .mapper .NumberFieldMapper ;
3739
3840import java .io .IOException ;
41+ import java .net .InetAddress ;
42+ import java .util .Arrays ;
3943import java .util .HashMap ;
4044import java .util .HashSet ;
4145import java .util .List ;
@@ -65,12 +69,15 @@ public void testStarTreeKeywordDocValues() throws IOException {
6569 doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
6670 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
6771 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
72+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
6873 iw .addDocument (doc );
6974 doc = new Document ();
7075 doc .add (new StringField ("_id" , "2" , Field .Store .NO ));
7176 doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
7277 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
7378 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+
7481 iw .addDocument (doc );
7582 iw .flush ();
7683 iw .deleteDocuments (new Term ("_id" , "2" ));
@@ -80,12 +87,14 @@ public void testStarTreeKeywordDocValues() throws IOException {
8087 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
8188 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
8289 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
90+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
8391 iw .addDocument (doc );
8492 doc = new Document ();
8593 doc .add (new StringField ("_id" , "4" , Field .Store .NO ));
8694 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
8795 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
8896 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
97+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
8998 iw .addDocument (doc );
9099 iw .flush ();
91100 iw .deleteDocuments (new Term ("_id" , "4" ));
@@ -166,6 +175,9 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
166175
167176 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef (keyword2Value )));
168177 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+ );
169181 iw .addDocument (doc );
170182 documents .put (id , doc );
171183 }
@@ -221,9 +233,7 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
221233 SortedSetStarTreeValuesIterator k1 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator (
222234 "keyword1"
223235 );
224- SortedSetStarTreeValuesIterator k2 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator (
225- "keyword2"
226- );
236+ SortedSetStarTreeValuesIterator k2 = (SortedSetStarTreeValuesIterator ) starTreeValues .getDimensionValuesIterator ("ip1" );
227237 for (StarTreeDocument starDoc : actualStarTreeDocuments ) {
228238 String keyword1 = null ;
229239 if (starDoc .dimensions [0 ] != null ) {
@@ -232,7 +242,11 @@ public void testStarTreeKeywordDocValuesWithDeletions() throws IOException {
232242
233243 String keyword2 = null ;
234244 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 ();
236250 }
237251 double metric = (double ) starDoc .metrics [0 ];
238252 if (map .containsKey (keyword1 + "-" + keyword2 )) {
@@ -254,21 +268,28 @@ public void testStarKeywordDocValuesWithMissingDocs() throws IOException {
254268 Document doc = new Document ();
255269 doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
256270 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+
257273 iw .addDocument (doc );
258274 doc = new Document ();
259275 doc .add (new SortedNumericDocValuesField ("sndv" , 1 ));
260276 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text22" )));
277+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.11" )))));
261278 iw .addDocument (doc );
262279 iw .forceMerge (1 );
263280 doc = new Document ();
264281 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
265282 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
266283 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+
267286 iw .addDocument (doc );
268287 doc = new Document ();
269288 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
270289 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
271290 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+
272293 iw .addDocument (doc );
273294 iw .forceMerge (1 );
274295 iw .close ();
@@ -340,11 +361,14 @@ public void testStarKeywordDocValuesWithMissingDocsInSegment() throws IOExceptio
340361 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
341362 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text1" )));
342363 doc .add (new SortedSetDocValuesField ("keyword2" , new BytesRef ("text2" )));
364+ doc .add (new SortedSetDocValuesField ("ip1" , new BytesRef (InetAddressPoint .encode (InetAddresses .forString ("10.10.10.10" )))));
343365 iw .addDocument (doc );
344366 doc = new Document ();
345367 doc .add (new SortedNumericDocValuesField ("sndv" , 2 ));
346368 doc .add (new SortedSetDocValuesField ("keyword1" , new BytesRef ("text11" )));
347369 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+
348372 iw .addDocument (doc );
349373 iw .forceMerge (1 );
350374 iw .close ();
@@ -538,7 +562,7 @@ protected XContentBuilder getMapping() throws IOException {
538562 b .field ("name" , "keyword1" );
539563 b .endObject ();
540564 b .startObject ();
541- b .field ("name" , "keyword2 " );
565+ b .field ("name" , "ip1 " );
542566 b .endObject ();
543567 b .endArray ();
544568 b .startArray ("metrics" );
@@ -566,6 +590,9 @@ protected XContentBuilder getMapping() throws IOException {
566590 b .startObject ("keyword2" );
567591 b .field ("type" , "keyword" );
568592 b .endObject ();
593+ b .startObject ("ip1" );
594+ b .field ("type" , "ip" );
595+ b .endObject ();
569596 b .endObject ();
570597 });
571598 }
0 commit comments