Skip to content

Add missing fields for IpProperty #6088

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
Jan 31, 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
9 changes: 9 additions & 0 deletions src/Nest/Mapping/Types/Specialized/Ip/IpAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ public string NullValue
set => Self.NullValue = value;
}

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

double? IIpProperty.Boost { get; set; }
bool? IIpProperty.Index { get; set; }
string IIpProperty.NullValue { get; set; }
private IIpProperty Self => this;
bool? IIpProperty.IgnoreMalformed { get; set; }
IInlineScript IIpProperty.Script { get; set; }
OnScriptError? IIpProperty.OnScriptError { get; set; }
}
}
49 changes: 49 additions & 0 deletions src/Nest/Mapping/Types/Specialized/Ip/IpProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ public interface IIpProperty : IDocValuesProperty

[DataMember(Name ="null_value")]
string NullValue { get; set; }

/// <summary>
/// If <c>true</c>, malformed IP addresses are ignored. If <c>false</c> (default), malformed IP addresses throw an exception and reject the whole document.
/// Note that this cannot be set if the script parameter is used.
/// </summary>
[DataMember(Name = "ignore_malformed")]
bool? IgnoreMalformed { 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. Scripts can only be configured on long and double field types.
/// </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="IIpProperty"/>
Expand All @@ -35,6 +58,15 @@ public IpProperty() : base(FieldType.Ip) { }
public double? Boost { get; set; }
public bool? Index { get; set; }
public string NullValue { get; set; }

/// <inheritdoc />
public bool? IgnoreMalformed { get; set; }

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

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

/// <inheritdoc cref="IIpProperty"/>
Expand All @@ -48,12 +80,29 @@ public IpPropertyDescriptor() : base(FieldType.Ip) { }
double? IIpProperty.Boost { get; set; }
bool? IIpProperty.Index { get; set; }
string IIpProperty.NullValue { get; set; }
bool? IIpProperty.IgnoreMalformed { get; set; }
IInlineScript IIpProperty.Script { get; set; }
OnScriptError? IIpProperty.OnScriptError { get; set; }

public IpPropertyDescriptor<T> Index(bool? index = true) => Assign(index, (a, v) => a.Index = v);

[Obsolete("The server always treated this as a noop and has been removed in 7.10")]
public IpPropertyDescriptor<T> Boost(double? boost) => Assign(boost, (a, v) => a.Boost = v);

public IpPropertyDescriptor<T> NullValue(string nullValue) => Assign(nullValue, (a, v) => a.NullValue = v);

public IpPropertyDescriptor<T> IgnoreMalformed(bool? ignoreMalformed = true) => Assign(ignoreMalformed, (a, v) => a.IgnoreMalformed = v);

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

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

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

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