Skip to content

Commit d9df17c

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.
1 parent fa80759 commit d9df17c

File tree

6 files changed

+122
-47
lines changed

6 files changed

+122
-47
lines changed

src/Nest/Mapping/Visitor/IMappingVisitor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface IMappingVisitor
3232
void Visit(ILongRangeProperty property);
3333
void Visit(IDoubleRangeProperty property);
3434
void Visit(IDateRangeProperty property);
35+
void Visit(IIpRangeProperty property);
3536
}
3637

3738
public class NoopMappingVisitor : IMappingVisitor
@@ -87,5 +88,7 @@ public virtual void Visit(ILongRangeProperty property) { }
8788
public virtual void Visit(IDoubleRangeProperty property) { }
8889

8990
public virtual void Visit(IDateRangeProperty property) { }
91+
92+
public virtual void Visit(IIpRangeProperty property) { }
9093
}
9194
}

src/Nest/Mapping/Visitor/IPropertyVisitor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ public interface IPropertyVisitor
2424
void Visit(IIpProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2525
void Visit(IMurmur3HashProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2626
void Visit(ITokenCountProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
27-
27+
void Visit(IPercolatorProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
28+
void Visit(IIntegerRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
29+
void Visit(IFloatRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
30+
void Visit(ILongRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
31+
void Visit(IDoubleRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
32+
void Visit(IDateRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
33+
void Visit(IIpRangeProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2834
void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);
2935

3036
IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute);

src/Nest/Mapping/Visitor/MappingWalker.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ public void Accept(IProperties properties)
221221
this.Accept(t.Fields);
222222
});
223223
break;
224+
case FieldType.IpRange:
225+
Visit<IIpRangeProperty>(field, t =>
226+
{
227+
this._visitor.Visit(t);
228+
this.Accept(t.Fields);
229+
});
230+
break;
224231
}
225232
}
226233
}

src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs

Lines changed: 94 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ 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+
3563
public virtual void Visit(IIpProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute)
3664
{
3765
}
@@ -78,52 +106,72 @@ public virtual void Visit(IStringProperty type, PropertyInfo propertyInfo, Elast
78106

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

src/Nest/Mapping/Visitor/PropertyWalker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ private IProperty InferProperty(Type type)
162162
if (type == typeof(IpAddressRange))
163163
return new IpRangeProperty();
164164

165+
if (type == typeof(QueryContainer))
166+
return new PercolatorProperty();
167+
165168
return new ObjectProperty();
166169
}
167170

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ protected override void ExpectResponse(IGetMappingResponse response)
6363
visitor.CountsShouldContainKeyAndCountBe("integer_range", 1);
6464
visitor.CountsShouldContainKeyAndCountBe("double_range", 1);
6565
visitor.CountsShouldContainKeyAndCountBe("long_range", 1);
66+
67+
if (TestClient.VersionUnderTestSatisfiedBy(">=5.5.0"))
68+
visitor.CountsShouldContainKeyAndCountBe("ip_range", 1);
6669
}
6770
}
6871
}
@@ -205,6 +208,11 @@ public void Visit(IDateRangeProperty property)
205208
Increment("date_range");
206209
}
207210

211+
public void Visit(IIpRangeProperty property)
212+
{
213+
Increment("ip_range");
214+
}
215+
208216
public void Visit(IMurmur3HashProperty mapping)
209217
{
210218
Increment("murmur3");

0 commit comments

Comments
 (0)