Skip to content

Commit 96f36d0

Browse files
authored
Add script to GeoPointProperty (#6559)
1 parent 47147bf commit 96f36d0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointAttribute.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,23 @@ public bool IgnoreZValue
2222
set => Self.IgnoreZValue = value;
2323
}
2424

25+
public IInlineScript Script
26+
{
27+
get => Self.Script;
28+
set => Self.Script = value;
29+
}
30+
31+
public OnScriptError OnScriptError
32+
{
33+
get => Self.OnScriptError.GetValueOrDefault();
34+
set => Self.OnScriptError = value;
35+
}
36+
2537
bool? IGeoPointProperty.IgnoreMalformed { get; set; }
2638
bool? IGeoPointProperty.IgnoreZValue { get; set; }
2739
GeoLocation IGeoPointProperty.NullValue { get; set; }
40+
IInlineScript IGeoPointProperty.Script { get; set; }
41+
OnScriptError? IGeoPointProperty.OnScriptError { get; set; }
2842
private IGeoPointProperty Self => this;
2943
}
3044
}

src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointProperty.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Diagnostics;
67
using System.Runtime.Serialization;
78
using Elasticsearch.Net.Utf8Json;
@@ -37,6 +38,22 @@ public interface IGeoPointProperty : IDocValuesProperty
3738
/// </summary>
3839
[DataMember(Name ="null_value")]
3940
GeoLocation NullValue { get; set; }
41+
42+
/// <summary>
43+
/// If this parameter is set, then the field will index values generated by this script, rather than reading the values directly from
44+
/// the source. If a value is set for this field on the input document, then the document will be rejected with an error. Scripts are
45+
/// in the same format as their runtime equivalent, and should emit points as a pair of (lat, lon) double values.
46+
/// </summary>
47+
[DataMember(Name = "script")]
48+
IInlineScript Script { get; set; }
49+
50+
/// <summary>
51+
/// Defines what to do if the script defined by the `script` parameter throws an error at indexing time.Accepts `reject` (default), which
52+
/// will cause the entire document to be rejected, and `ignore`, which will register the field in the document's ignored metadata field and
53+
/// continue indexing.This parameter can only be set if the `script` field is also set.
54+
/// </summary>
55+
[DataMember(Name = "on_script_error")]
56+
OnScriptError? OnScriptError { get; set; }
4057
}
4158

4259
/// <inheritdoc cref="IGeoPointProperty"/>
@@ -53,6 +70,12 @@ public GeoPointProperty() : base(FieldType.GeoPoint) { }
5370

5471
/// <inheritdoc />
5572
public GeoLocation NullValue { get; set; }
73+
74+
/// <inheritdoc />
75+
public IInlineScript Script { get; set; }
76+
77+
/// <inheritdoc />
78+
public OnScriptError? OnScriptError { get; set; }
5679
}
5780

5881
/// <inheritdoc cref="IGeoPointProperty"/>
@@ -66,6 +89,8 @@ public GeoPointPropertyDescriptor() : base(FieldType.GeoPoint) { }
6689
bool? IGeoPointProperty.IgnoreMalformed { get; set; }
6790
bool? IGeoPointProperty.IgnoreZValue { get; set; }
6891
GeoLocation IGeoPointProperty.NullValue { get; set; }
92+
IInlineScript IGeoPointProperty.Script { get; set; }
93+
OnScriptError? IGeoPointProperty.OnScriptError { get; set; }
6994

7095
/// <inheritdoc cref="IGeoPointProperty.IgnoreMalformed" />
7196
public GeoPointPropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) => Assign(ignoreMalformed, (a, v) => a.IgnoreMalformed = v);
@@ -75,5 +100,17 @@ public GeoPointPropertyDescriptor() : base(FieldType.GeoPoint) { }
75100

76101
/// <inheritdoc cref="IGeoPointProperty.NullValue" />
77102
public GeoPointPropertyDescriptor<T> NullValue(GeoLocation defaultValue) => Assign(defaultValue, (a, v) => a.NullValue = v);
103+
104+
/// <inheritdoc cref="INumberProperty.Script" />
105+
public GeoPointPropertyDescriptor<T> Script(IInlineScript inlineScript) => Assign(inlineScript, (a, v) => a.Script = v);
106+
107+
/// <inheritdoc cref="INumberProperty.Script" />
108+
public GeoPointPropertyDescriptor<T> Script(string source) => Assign(source, (a, v) => a.Script = new InlineScript(source));
109+
110+
/// <inheritdoc cref="INumberProperty.Script" />
111+
public GeoPointPropertyDescriptor<T> Script(Func<InlineScriptDescriptor, IInlineScript> selector) => Assign(selector, (a, v) => a.Script = v?.Invoke(new InlineScriptDescriptor()));
112+
113+
/// <inheritdoc cref="INumberProperty.OnScriptError" />
114+
public GeoPointPropertyDescriptor<T> OnScriptError(OnScriptError? onScriptError) => Assign(onScriptError, (a, v) => a.OnScriptError = v);
78115
}
79116
}

0 commit comments

Comments
 (0)