Skip to content

Commit

Permalink
Add first_only to geoip processor (#4410)
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam authored and github-actions[bot] committed Feb 21, 2020
1 parent 9a08447 commit 9358184
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Nest/Ingest/Processors/Plugins/GeoIpProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public interface IGeoIpProcessor : IProcessor

[DataMember(Name ="target_field")]
Field TargetField { get; set; }

/// <summary>
/// If <c>true</c>, only first found geoip data will be returned, even if field contains array.
/// Defaults to <c>true</c>
/// <para />
/// Available in Elasticsearch 7.6.0+
/// </summary>
[DataMember(Name = "first_only")]
bool? FirstOnly { get; set; }
}

/// <summary>
Expand All @@ -58,6 +67,10 @@ public class GeoIpProcessor : ProcessorBase, IGeoIpProcessor
public IEnumerable<string> Properties { get; set; }

public Field TargetField { get; set; }

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

protected override string Name => "geoip";
}

Expand All @@ -81,13 +94,14 @@ public class GeoIpProcessorDescriptor<T>
bool? IGeoIpProcessor.IgnoreMissing { get; set; }
IEnumerable<string> IGeoIpProcessor.Properties { get; set; }
Field IGeoIpProcessor.TargetField { get; set; }
bool? IGeoIpProcessor.FirstOnly { get; set; }

public GeoIpProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);

public GeoIpProcessorDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> objectPath) =>
Assign(objectPath, (a, v) => a.Field = v);

/// <inheritdoc />
/// <inheritdoc cref="IGeoIpProcessor.IgnoreMissing"/>
public GeoIpProcessorDescriptor<T> IgnoreMissing(bool? ignoreMissing = true) => Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v);

public GeoIpProcessorDescriptor<T> TargetField(Field field) => Assign(field, (a, v) => a.TargetField = v);
Expand All @@ -100,5 +114,8 @@ public GeoIpProcessorDescriptor<T> TargetField<TValue>(Expression<Func<T, TValue
public GeoIpProcessorDescriptor<T> Properties(IEnumerable<string> properties) => Assign(properties, (a, v) => a.Properties = v);

public GeoIpProcessorDescriptor<T> Properties(params string[] properties) => Assign(properties, (a, v) => a.Properties = v);

/// <inheritdoc cref="IGeoIpProcessor.FirstOnly"/>
public GeoIpProcessorDescriptor<T> FirstOnly(bool? firstOnly = true) => Assign(firstOnly, (a, v) => a.FirstOnly = v);
}
}

0 comments on commit 9358184

Please sign in to comment.