8
8
9
9
import org .apache .lucene .document .InetAddressPoint ;
10
10
import org .apache .lucene .index .LeafReaderContext ;
11
+ import org .apache .lucene .util .BytesRef ;
11
12
import org .elasticsearch .common .bytes .BytesArray ;
12
13
import org .elasticsearch .common .bytes .BytesReference ;
13
14
import org .elasticsearch .common .network .InetAddresses ;
22
23
import org .elasticsearch .search .aggregations .support .ValuesSourceType ;
23
24
import org .elasticsearch .xpack .runtimefields .IpScriptFieldScript ;
24
25
25
- import java .io .IOException ;
26
26
import java .net .InetAddress ;
27
27
28
28
public class ScriptIpFieldData extends ScriptBinaryFieldData {
@@ -54,7 +54,7 @@ public ScriptBinaryLeafFieldData loadDirect(LeafReaderContext context) throws Ex
54
54
return new ScriptBinaryLeafFieldData () {
55
55
@ Override
56
56
public ScriptDocValues <String > getScriptValues () {
57
- return new IpScriptDocValues (script );
57
+ return new IpScriptDocValues (getBytesValues () );
58
58
}
59
59
60
60
@ Override
@@ -70,46 +70,19 @@ public ValuesSourceType getValuesSourceType() {
70
70
}
71
71
72
72
/**
73
- * We can't share {@link IpFieldMapper.IpFieldType.IpScriptDocValues} because it
74
- * is based on global ordinals and we don't have those.
73
+ * Doc values implementation for ips. We can't share
74
+ * {@link IpFieldMapper.IpFieldType.IpScriptDocValues} because it is based
75
+ * on global ordinals and we don't have those.
75
76
*/
76
- public static class IpScriptDocValues extends ScriptDocValues <String > {
77
- private final IpScriptFieldScript script ;
78
-
79
- public IpScriptDocValues (IpScriptFieldScript script ) {
80
- this .script = script ;
77
+ public static class IpScriptDocValues extends ScriptDocValues .Strings {
78
+ public IpScriptDocValues (SortedBinaryDocValues in ) {
79
+ super (in );
81
80
}
82
81
83
82
@ Override
84
- public void setNextDocId (int docId ) throws IOException {
85
- script .runForDoc (docId );
86
- }
87
-
88
- public String getValue () {
89
- if (size () == 0 ) {
90
- return null ;
91
- }
92
- return get (0 );
93
- }
94
-
95
- @ Override
96
- public String get (int index ) {
97
- if (index >= size ()) {
98
- if (size () == 0 ) {
99
- throw new IllegalStateException (
100
- "A document doesn't have a value for a field! "
101
- + "Use doc[<field>].size()==0 to check if a document is missing a field!"
102
- );
103
- }
104
- throw new ArrayIndexOutOfBoundsException ("There are only [" + size () + "] values." );
105
- }
106
- InetAddress addr = InetAddressPoint .decode (BytesReference .toBytes (new BytesArray (script .values ()[index ])));
83
+ protected String bytesToString (BytesRef bytes ) {
84
+ InetAddress addr = InetAddressPoint .decode (BytesReference .toBytes (new BytesArray (bytes )));
107
85
return InetAddresses .toAddrString (addr );
108
86
}
109
-
110
- @ Override
111
- public int size () {
112
- return script .count ();
113
- }
114
87
}
115
88
}
0 commit comments