19
19
20
20
package org .elasticsearch .join .mapper ;
21
21
22
- import org .apache .lucene .document .FieldType ;
23
- import org .apache .lucene .index .IndexOptions ;
24
22
import org .apache .lucene .search .Query ;
25
- import org .apache .lucene .util .BytesRef ;
26
23
import org .elasticsearch .index .fielddata .IndexFieldData ;
27
- import org .elasticsearch .index .fielddata .plain .SortedSetOrdinalsIndexFieldData ;
28
- import org .elasticsearch .index .mapper .FieldMapper ;
29
24
import org .elasticsearch .index .mapper .MapperService ;
25
+ import org .elasticsearch .index .mapper .MetadataFieldMapper ;
30
26
import org .elasticsearch .index .mapper .ParseContext ;
31
27
import org .elasticsearch .index .mapper .StringFieldType ;
32
28
import org .elasticsearch .index .mapper .TextSearchInfo ;
33
29
import org .elasticsearch .index .mapper .ValueFetcher ;
34
30
import org .elasticsearch .index .query .QueryShardContext ;
35
- import org .elasticsearch .search .aggregations .support .CoreValuesSourceType ;
36
31
import org .elasticsearch .search .lookup .SearchLookup ;
37
32
38
33
import java .io .IOException ;
39
34
import java .util .Collections ;
40
- import java .util .List ;
41
35
import java .util .function .Supplier ;
42
36
43
37
/**
47
41
* This class is also used to quickly retrieve the parent-join field defined in a mapping without
48
42
* specifying the name of the field.
49
43
*/
50
- public class MetaJoinFieldMapper extends FieldMapper {
44
+ public class MetaJoinFieldMapper extends MetadataFieldMapper {
45
+
51
46
static final String NAME = "_parent_join" ;
52
47
static final String CONTENT_TYPE = "parent_join" ;
53
48
54
- static class Defaults {
55
- public static final FieldType FIELD_TYPE = new FieldType ();
56
-
57
- static {
58
- FIELD_TYPE .setStored (false );
59
- FIELD_TYPE .setIndexOptions (IndexOptions .NONE );
60
- FIELD_TYPE .freeze ();
61
- }
62
- }
63
-
64
- static class Builder extends FieldMapper .Builder {
65
-
66
- final String joinField ;
67
-
68
- Builder (String joinField ) {
69
- super (NAME , Defaults .FIELD_TYPE );
70
- this .joinField = joinField ;
71
- }
72
-
73
- @ Override
74
- public MetaJoinFieldMapper build (BuilderContext context ) {
75
- return new MetaJoinFieldMapper (name , joinField );
76
- }
77
- }
78
-
79
49
public static class MetaJoinFieldType extends StringFieldType {
80
50
81
51
private final String joinField ;
@@ -92,22 +62,17 @@ public String typeName() {
92
62
93
63
@ Override
94
64
public IndexFieldData .Builder fielddataBuilder (String fullyQualifiedIndexName , Supplier <SearchLookup > searchLookup ) {
95
- failIfNoDocValues ();
96
- return new SortedSetOrdinalsIndexFieldData .Builder (name (), CoreValuesSourceType .BYTES );
65
+ throw new UnsupportedOperationException ("Cannot load field data for metadata field [" + NAME + "]" );
97
66
}
98
67
99
68
@ Override
100
69
public ValueFetcher valueFetcher (MapperService mapperService , SearchLookup searchLookup , String format ) {
101
- throw new UnsupportedOperationException ("Cannot fetch values for metadata field [" + typeName () + "]." );
70
+ throw new UnsupportedOperationException ("Cannot fetch values for metadata field [" + NAME + "]." );
102
71
}
103
72
104
73
@ Override
105
74
public Object valueForDisplay (Object value ) {
106
- if (value == null ) {
107
- return null ;
108
- }
109
- BytesRef binaryValue = (BytesRef ) value ;
110
- return binaryValue .utf8ToString ();
75
+ throw new UnsupportedOperationException ();
111
76
}
112
77
113
78
public String getJoinField () {
@@ -120,8 +85,8 @@ public Query existsQuery(QueryShardContext context) {
120
85
}
121
86
}
122
87
123
- MetaJoinFieldMapper (String name , String joinField ) {
124
- super (name , Defaults . FIELD_TYPE , new MetaJoinFieldType (joinField ), MultiFields . empty (), CopyTo . empty ( ));
88
+ MetaJoinFieldMapper (String joinField ) {
89
+ super (new MetaJoinFieldType (joinField ));
125
90
}
126
91
127
92
@ Override
@@ -134,10 +99,6 @@ protected MetaJoinFieldMapper clone() {
134
99
return (MetaJoinFieldMapper ) super .clone ();
135
100
}
136
101
137
- @ Override
138
- protected void mergeOptions (FieldMapper other , List <String > conflicts ) {
139
- }
140
-
141
102
@ Override
142
103
protected void parseCreateField (ParseContext context ) throws IOException {
143
104
throw new IllegalStateException ("Should never be called" );
0 commit comments