Skip to content

Commit a1833b5

Browse files
committed
Reverted mappings of ingest back to alpha1
CRUD/PUT tests are succeeding, fixed the Processor deserialization so we can read IProcessors being returned. Added a test for adding a pipeline to an Index() call
1 parent db3ce48 commit a1833b5

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

Diff for: src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReserializeJsonConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ protected void Reserialize(JsonWriter writer, object value, JsonSerializer seria
5858
writer.WriteEndObject();
5959
}
6060
}
61-
}
61+
}

Diff for: src/Nest/Ingest/ProcessorJsonConverter.cs

+9
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,14 @@ protected override void SerializeJson(JsonWriter writer, object value, IProcesso
2323
}
2424
writer.WriteEndObject();
2525
}
26+
27+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
28+
{
29+
if (reader.TokenType != JsonToken.StartObject) return null;
30+
reader.Read(); //property name of processor type
31+
if (reader.TokenType != JsonToken.PropertyName) return null;
32+
reader.Read();
33+
return base.ReadJson(reader, objectType, existingValue, serializer);
34+
}
2635
}
2736
}

Diff for: src/Nest/Ingest/Processors/DateProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace Nest
1212
[JsonConverter(typeof(ProcessorJsonConverter<DateProcessor>))]
1313
public interface IDateProcessor : IProcessor
1414
{
15-
[JsonProperty("field")]
15+
[JsonProperty("match_field")]
1616
Field Field { get; set; }
1717

1818
[JsonProperty("target_field")]
1919
Field TargetField { get; set; }
2020

21-
[JsonProperty("formats")]
21+
[JsonProperty("match_formats")]
2222
IEnumerable<string> Formats { get; set; }
2323

2424
[JsonProperty("timezone")]

Diff for: src/Nest/Ingest/Processors/RenameProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IRenameProcessor : IProcessor
1616
[JsonProperty("field")]
1717
Field Field { get; set; }
1818

19-
[JsonProperty("target_field")]
19+
[JsonProperty("to")]
2020
Field TargetField { get; set; }
2121
}
2222

Diff for: src/Nest/Ingest/Processors/UppercaseProcessor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface IUppercaseProcessor : IProcessor
1919
public class UppercaseProcessor : ProcessorBase, IUppercaseProcessor
2020
{
2121
protected override string Name => "uppercase";
22+
[JsonProperty("field")]
2223
public Field Field { get; set; }
2324
}
2425

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
using Newtonsoft.Json.Linq;
8+
using Tests.Framework;
9+
using Tests.Framework.Integration;
10+
using Tests.Framework.MockData;
11+
using Xunit;
12+
13+
namespace Tests.Document.Single.Index
14+
{
15+
[Collection(IntegrationContext.Indexing)]
16+
public class IndexIngestApiTests :
17+
ApiIntegrationTestBase<IIndexResponse, IIndexRequest<Project>, IndexDescriptor<Project>, IndexRequest<Project>>
18+
{
19+
private string PipelineId { get; } = "pipeline-" + Guid.NewGuid().ToString("N").Substring(0, 8);
20+
21+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
22+
{
23+
client.PutPipeline(new PutPipelineRequest(this.PipelineId)
24+
{
25+
Description = "Index pipeline test",
26+
Processors = new List<IProcessor>
27+
{
28+
new RenameProcessor
29+
{
30+
TargetField = "lastSeen",
31+
Field = "lastActivity"
32+
}
33+
}
34+
});
35+
36+
37+
38+
}
39+
40+
private Project Document => new Project
41+
{
42+
State = StateOfBeing.Stable,
43+
Name = CallIsolatedValue,
44+
StartedOn = FixedDate,
45+
LastActivity = FixedDate,
46+
CuratedTags = new List<Tag> {new Tag {Name = "x", Added = FixedDate}},
47+
};
48+
49+
public IndexIngestApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage)
50+
{
51+
}
52+
53+
protected override LazyResponses ClientUsage() => Calls(
54+
fluent: (client, f) => client.Index<Project>(this.Document, f),
55+
fluentAsync: (client, f) => client.IndexAsync<Project>(this.Document, f),
56+
request: (client, r) => client.Index(r),
57+
requestAsync: (client, r) => client.IndexAsync(r)
58+
);
59+
60+
protected override bool ExpectIsValid => true;
61+
protected override int ExpectStatusCode => 201;
62+
protected override HttpMethod HttpMethod => HttpMethod.PUT;
63+
64+
protected override string UrlPath
65+
=> $"/project/project/{CallIsolatedValue}?consistency=quorum&op_type=index&refresh=true&routing=route";
66+
67+
protected override bool SupportsDeserialization => false;
68+
69+
protected override object ExpectJson =>
70+
new
71+
{
72+
name = CallIsolatedValue,
73+
state = "Stable",
74+
startedOn = FixedDate,
75+
lastActivity = FixedDate,
76+
curatedTags = new[] {new {name = "x", added = FixedDate}},
77+
};
78+
79+
protected override IndexDescriptor<Project> NewDescriptor() => new IndexDescriptor<Project>(this.Document);
80+
81+
protected override Func<IndexDescriptor<Project>, IIndexRequest<Project>> Fluent => s => s
82+
.Consistency(Consistency.Quorum)
83+
.OpType(OpType.Index)
84+
.Refresh()
85+
.Pipeline(this.PipelineId)
86+
.Routing("route");
87+
88+
protected override IndexRequest<Project> Initializer =>
89+
new IndexRequest<Project>(this.Document)
90+
{
91+
Refresh = true,
92+
OpType = OpType.Index,
93+
Consistency = Consistency.Quorum,
94+
Routing = "route",
95+
Pipeline = this.PipelineId
96+
};
97+
98+
}
99+
100+
}

Diff for: src/Tests/Ingest/PutPipeline/PutPipelineApiTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ protected override LazyResponses ClientUsage() => Calls(
5656
{
5757
date = new
5858
{
59-
field = "startedOn",
59+
match_field = "startedOn",
6060
target_field = "timestamp",
61-
formats = new [] { "dd/MM/yyyy hh:mm:ss" },
61+
match_formats = new [] { "dd/MM/yyyy hh:mm:ss" },
6262
timezone = "Europe/Amsterdam"
6363
}
6464
},
@@ -135,7 +135,7 @@ protected override LazyResponses ClientUsage() => Calls(
135135
rename = new
136136
{
137137
field = "leadDeveloper",
138-
target_field = "projectLead"
138+
to = "projectLead"
139139
}
140140
},
141141
new

Diff for: src/Tests/Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
<Compile Include=".\Mapping\Types\Core\Number\NumberMappingTests.cs" />
322322
<Compile Include="Aggregations\AggregationVisitorTests.cs" />
323323
<Compile Include="CodeStandards\Serialization\Converters.doc.cs" />
324+
<Compile Include="Document\Single\Index\IndexIngestApiTests.cs" />
324325
<Compile Include="Framework\MockData\Tag.cs" />
325326
<Compile Include="Framework\MockResponses\SniffingResponse.cs" />
326327
<Compile Include="Indices\IndexManagement\OpenCloseIndex\OpenIndex\OpenIndexApiTests.cs" />

Diff for: src/Tests/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
22
mode: m
33
# the elasticsearch version that should be started
4-
elasticsearch_version: 5.0.0-alpha2-SNAPSHOT
4+
elasticsearch_version: 5.0.0-alpha1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
66
force_reseed: true
77
# do not spawn nodes as part of the test setup but rely on a manually started es node being up

0 commit comments

Comments
 (0)