Skip to content

Add script to GeoPointProperty #6559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,23 @@ public bool IgnoreZValue
set => Self.IgnoreZValue = value;
}

public IInlineScript Script
{
get => Self.Script;
set => Self.Script = value;
}

public OnScriptError OnScriptError
{
get => Self.OnScriptError.GetValueOrDefault();
set => Self.OnScriptError = value;
}

bool? IGeoPointProperty.IgnoreMalformed { get; set; }
bool? IGeoPointProperty.IgnoreZValue { get; set; }
GeoLocation IGeoPointProperty.NullValue { get; set; }
IInlineScript IGeoPointProperty.Script { get; set; }
OnScriptError? IGeoPointProperty.OnScriptError { get; set; }
private IGeoPointProperty Self => this;
}
}
37 changes: 37 additions & 0 deletions src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;
Expand Down Expand Up @@ -37,6 +38,22 @@ public interface IGeoPointProperty : IDocValuesProperty
/// </summary>
[DataMember(Name ="null_value")]
GeoLocation NullValue { get; set; }

/// <summary>
/// If this parameter is set, then the field will index values generated by this script, rather than reading the values directly from
/// 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
/// in the same format as their runtime equivalent, and should emit points as a pair of (lat, lon) double values.
/// </summary>
[DataMember(Name = "script")]
IInlineScript Script { get; set; }

/// <summary>
/// Defines what to do if the script defined by the `script` parameter throws an error at indexing time.Accepts `reject` (default), which
/// will cause the entire document to be rejected, and `ignore`, which will register the field in the document's ignored metadata field and
/// continue indexing.This parameter can only be set if the `script` field is also set.
/// </summary>
[DataMember(Name = "on_script_error")]
OnScriptError? OnScriptError { get; set; }
}

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

/// <inheritdoc />
public GeoLocation NullValue { get; set; }

/// <inheritdoc />
public IInlineScript Script { get; set; }

/// <inheritdoc />
public OnScriptError? OnScriptError { get; set; }
}

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

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

/// <inheritdoc cref="IGeoPointProperty.NullValue" />
public GeoPointPropertyDescriptor<T> NullValue(GeoLocation defaultValue) => Assign(defaultValue, (a, v) => a.NullValue = v);

/// <inheritdoc cref="INumberProperty.Script" />
public GeoPointPropertyDescriptor<T> Script(IInlineScript inlineScript) => Assign(inlineScript, (a, v) => a.Script = v);

/// <inheritdoc cref="INumberProperty.Script" />
public GeoPointPropertyDescriptor<T> Script(string source) => Assign(source, (a, v) => a.Script = new InlineScript(source));

/// <inheritdoc cref="INumberProperty.Script" />
public GeoPointPropertyDescriptor<T> Script(Func<InlineScriptDescriptor, IInlineScript> selector) => Assign(selector, (a, v) => a.Script = v?.Invoke(new InlineScriptDescriptor()));

/// <inheritdoc cref="INumberProperty.OnScriptError" />
public GeoPointPropertyDescriptor<T> OnScriptError(OnScriptError? onScriptError) => Assign(onScriptError, (a, v) => a.OnScriptError = v);
}
}