Skip to content

Commit 53234bc

Browse files
committed
Add Visit methods for *_range properties (#3218)
This commit adds mapping and property visitor methods for the range data types. Map a QueryContainer property as a percolator data type by default. (cherry picked from commit 36208b1)
1 parent b338fa0 commit 53234bc

File tree

6 files changed

+128
-41
lines changed

6 files changed

+128
-41
lines changed

src/Nest/Mapping/Visitor/IMappingVisitor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public interface IMappingVisitor
2626
void Visit(ILongRangeProperty property);
2727
void Visit(IDoubleRangeProperty property);
2828
void Visit(IDateRangeProperty property);
29+
void Visit(IIpRangeProperty property);
2930
void Visit(IJoinProperty property);
3031
}
3132

@@ -75,6 +76,8 @@ public virtual void Visit(IDoubleRangeProperty property) { }
7576

7677
public virtual void Visit(IDateRangeProperty property) { }
7778

79+
public virtual void Visit(IIpRangeProperty property) { }
80+
7881
public virtual void Visit(IJoinProperty property) { }
7982
}
8083
}

src/Nest/Mapping/Visitor/IPropertyVisitor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public interface IPropertyVisitor
1818
void Visit(IIpProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
1919
void Visit(IMurmur3HashProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2020
void Visit(ITokenCountProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
21+
void Visit(IPercolatorProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
22+
void Visit(IIntegerRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
23+
void Visit(IFloatRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
24+
void Visit(ILongRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
25+
void Visit(IDoubleRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
26+
void Visit(IDateRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
27+
void Visit(IIpRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
28+
void Visit(IJoinProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2129

2230
void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2331

src/Nest/Mapping/Visitor/MappingWalker.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ public void Accept(IProperties properties)
201201
this.Accept(t.Fields);
202202
});
203203
break;
204+
case FieldType.IpRange:
205+
Visit<IIpRangeProperty>(field, t =>
206+
{
207+
this._visitor.Visit(t);
208+
this.Accept(t.Fields);
209+
});
210+
break;
204211
case FieldType.Join:
205212
Visit<IJoinProperty>(field, t =>
206213
{

src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs

Lines changed: 101 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ public virtual void Visit(ITokenCountProperty type, PropertyInfo propertyInfo, E
3232
{
3333
}
3434

35+
public void Visit(IPercolatorProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
36+
{
37+
}
38+
39+
public void Visit(IIntegerRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
40+
{
41+
}
42+
43+
public void Visit(IFloatRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
44+
{
45+
}
46+
47+
public void Visit(ILongRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
48+
{
49+
}
50+
51+
public void Visit(IDoubleRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
52+
{
53+
}
54+
55+
public void Visit(IDateRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
56+
{
57+
}
58+
59+
public void Visit(IIpRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
60+
{
61+
}
62+
63+
public void Visit(IJoinProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
64+
{
65+
}
66+
3567
public virtual void Visit(IIpProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
3668
{
3769
}
@@ -66,47 +98,75 @@ public virtual void Visit(IKeywordProperty type, PropertyInfo propertyInfo, Elas
6698

6799
public void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
68100
{
69-
if (type is INestedProperty nestedType)
70-
Visit(nestedType, propertyInfo, attribute);
71-
72-
if (type is IObjectProperty objectType)
73-
Visit(objectType, propertyInfo, attribute);
74-
75-
if (type is IBinaryProperty binaryType)
76-
Visit(binaryType, propertyInfo, attribute);
77-
78-
if (type is IBooleanProperty booleanType)
79-
Visit(booleanType, propertyInfo, attribute);
80-
81-
if (type is IDateProperty dateType)
82-
Visit(dateType, propertyInfo, attribute);
83-
84-
if (type is INumberProperty numberType)
85-
Visit(numberType, propertyInfo, attribute);
86-
87-
if (type is ITextProperty textType)
88-
Visit(textType, propertyInfo, attribute);
89-
90-
if (type is IKeywordProperty keywordType)
91-
Visit(keywordType, propertyInfo, attribute);
92-
93-
if (type is IGeoShapeProperty geoShapeType)
94-
Visit(geoShapeType, propertyInfo, attribute);
95-
96-
if (type is IGeoPointProperty geoPointType)
97-
Visit(geoPointType, propertyInfo, attribute);
98-
99-
if (type is ICompletionProperty completionType)
100-
Visit(completionType, propertyInfo, attribute);
101-
102-
if (type is IIpProperty ipType)
103-
Visit(ipType, propertyInfo, attribute);
104-
105-
if (type is IMurmur3HashProperty murmurType)
106-
Visit(murmurType, propertyInfo, attribute);
107-
108-
if (type is ITokenCountProperty tokenCountType)
109-
Visit(tokenCountType, propertyInfo, attribute);
101+
switch (type)
102+
{
103+
case INestedProperty nestedType:
104+
Visit(nestedType, propertyInfo, attribute);
105+
break;
106+
case IObjectProperty objectType:
107+
Visit(objectType, propertyInfo, attribute);
108+
break;
109+
case IBinaryProperty binaryType:
110+
Visit(binaryType, propertyInfo, attribute);
111+
break;
112+
case IBooleanProperty booleanType:
113+
Visit(booleanType, propertyInfo, attribute);
114+
break;
115+
case IDateProperty dateType:
116+
Visit(dateType, propertyInfo, attribute);
117+
break;
118+
case INumberProperty numberType:
119+
Visit(numberType, propertyInfo, attribute);
120+
break;
121+
case ITextProperty textType:
122+
Visit(textType, propertyInfo, attribute);
123+
break;
124+
case IKeywordProperty keywordType:
125+
Visit(keywordType, propertyInfo, attribute);
126+
break;
127+
case IGeoShapeProperty geoShapeType:
128+
Visit(geoShapeType, propertyInfo, attribute);
129+
break;
130+
case IGeoPointProperty geoPointType:
131+
Visit(geoPointType, propertyInfo, attribute);
132+
break;
133+
case ICompletionProperty completionType:
134+
Visit(completionType, propertyInfo, attribute);
135+
break;
136+
case IIpProperty ipType:
137+
Visit(ipType, propertyInfo, attribute);
138+
break;
139+
case IMurmur3HashProperty murmurType:
140+
Visit(murmurType, propertyInfo, attribute);
141+
break;
142+
case ITokenCountProperty tokenCountType:
143+
Visit(tokenCountType, propertyInfo, attribute);
144+
break;
145+
case IPercolatorProperty percolatorType:
146+
Visit(percolatorType, propertyInfo, attribute);
147+
break;
148+
case IJoinProperty joinType:
149+
Visit(joinType, propertyInfo, attribute);
150+
break;
151+
case IIntegerRangeProperty integerRangeType:
152+
Visit(integerRangeType, propertyInfo, attribute);
153+
break;
154+
case ILongRangeProperty longRangeType:
155+
Visit(longRangeType, propertyInfo, attribute);
156+
break;
157+
case IDoubleRangeProperty doubleRangeType:
158+
Visit(doubleRangeType, propertyInfo, attribute);
159+
break;
160+
case IFloatRangeProperty floatRangeType:
161+
Visit(floatRangeType, propertyInfo, attribute);
162+
break;
163+
case IDateRangeProperty dateRangeType:
164+
Visit(dateRangeType, propertyInfo, attribute);
165+
break;
166+
case IIpRangeProperty ipRangeType:
167+
Visit(ipRangeType, propertyInfo, attribute);
168+
break;
169+
}
110170
}
111171
}
112172
}

src/Nest/Mapping/Visitor/PropertyWalker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ private static IProperty InferProperty(PropertyInfo propertyInfo)
158158
if (type == typeof(IpAddressRange))
159159
return new IpRangeProperty();
160160

161+
if (type == typeof(QueryContainer))
162+
return new PercolatorProperty();
163+
161164
return new ObjectProperty();
162165
}
163166

src/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private static void AssertVisitedProperies(IGetMappingResponse response)
9999
visitor.CountsShouldContainKeyAndCountBe("float_range", 1);
100100
visitor.CountsShouldContainKeyAndCountBe("integer_range", 1);
101101
visitor.CountsShouldContainKeyAndCountBe("long_range", 1);
102+
visitor.CountsShouldContainKeyAndCountBe("ip_range", 1);
102103
visitor.CountsShouldContainKeyAndCountBe("nested", 1);
103104
}
104105
}
@@ -228,6 +229,11 @@ public void Visit(IDateRangeProperty property)
228229
Increment("date_range");
229230
}
230231

232+
public void Visit(IIpRangeProperty property)
233+
{
234+
Increment("ip_range");
235+
}
236+
231237
public void Visit(IJoinProperty property)
232238
{
233239
Increment("join");

0 commit comments

Comments
 (0)