Skip to content
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

Add ignore_missing to the remove processor #3441

Merged
merged 2 commits into from
Oct 17, 2018
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
25 changes: 19 additions & 6 deletions src/Nest/Ingest/Processors/RemoveProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Nest
{
Expand All @@ -14,25 +10,42 @@ public interface IRemoveProcessor : IProcessor
{
[JsonProperty("field")]
Field Field { get; set; }

/// <summary>
/// If <c>true</c> and <see cref="Field"/> does not exist or is null,
/// the processor quietly exits without modifying the document. Default is <c>false</c>
/// </summary>
[JsonProperty("ignore_missing")]
bool? IgnoreMissing { get; set; }
}

/// <inheritdoc cref="IRemoveProcessor" />
public class RemoveProcessor : ProcessorBase, IRemoveProcessor
{
protected override string Name => "remove";
/// <inheritdoc cref="IRemoveProcessor.Field" />
public Field Field { get; set; }
/// <inheritdoc cref="IRemoveProcessor.IgnoreMissing" />
public bool? IgnoreMissing { get; set; }
}

/// <inheritdoc cref="IRemoveProcessor" />
public class RemoveProcessorDescriptor<T>
: ProcessorDescriptorBase<RemoveProcessorDescriptor<T>, IRemoveProcessor>, IRemoveProcessor
where T : class
{
protected override string Name => "remove";

Field IRemoveProcessor.Field { get; set; }
bool? IRemoveProcessor.IgnoreMissing { get; set; }

/// <inheritdoc cref="IRemoveProcessor.Field" />
public RemoveProcessorDescriptor<T> Field(Field field) => Assign(a => a.Field = field);

public RemoveProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) =>
Assign(a => a.Field = objectPath);
/// <inheritdoc cref="IRemoveProcessor.Field" />
public RemoveProcessorDescriptor<T> Field(Expression<Func<T, object>> objectPath) => Assign(a => a.Field = objectPath);

/// <inheritdoc cref="IRemoveProcessor.IgnoreMissing" />
public RemoveProcessorDescriptor<T> IgnoreMissing(bool? ignoreMissing = true) => Assign(a => a.IgnoreMissing = ignoreMissing);
}
}
2 changes: 1 addition & 1 deletion src/Tests/Tests.Configuration/tests.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# tracked by git).

# mode either u (unit test), i (integration test) or m (mixed mode)
mode: u
mode: m
# the elasticsearch version that should be started
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
elasticsearch_version: 6.4.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using FluentAssertions;
using System;
using Tests.Core.Serialization;

namespace Tests.Core.Extensions
{
public static class SerializationTesterAssertionExtensions
{
public static void ShouldBeValid(this SerializationResult result, string message = null) =>
result.Success.Should().BeTrue("{0}", message + result);
public static void ShouldBeValid(this SerializationResult result, string message = null)
{
if (result.Success) return;
throw new Exception($@"Expected serialization to succeed but failed.
{(message ?? string.Empty) + result}
");
}

public static T AssertRoundTrip<T>(this SerializationTester tester, T @object, string message = null, bool preserveNullInExpected = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Framework;
using Tests.Framework.Integration;
using Tests.Framework.ManagedElasticsearch.Clusters;
using Xunit;

namespace Tests.Ingest.DeletePipeline
{
//integration test is part of PipelineCrudTests
public class DeletePipelineApiTests : ApiTestBase<ReadOnlyCluster, IDeletePipelineResponse, IDeletePipelineRequest, DeletePipelineDescriptor, DeletePipelineRequest>
{
public DeletePipelineApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
Expand Down
1 change: 1 addition & 0 deletions src/Tests/Tests/Ingest/GetPipeline/GetPipelineApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Tests.Ingest.GetPipeline
{
//integration test is part of PipelineCrudTests
public class GetPipelineApiTests : ApiTestBase<ReadOnlyCluster, IGetPipelineResponse, IGetPipelineRequest, GetPipelineDescriptor, GetPipelineRequest>
{
public GetPipelineApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
Expand Down
Loading