Skip to content

Commit 4f68104

Browse files
committed
Merge pull request #1391 from elastic/feature/field-names-mapping
fix #1352 add support for _field_names mapping
2 parents 9e20238 + 9fc6b74 commit 4f68104

File tree

7 files changed

+76
-0
lines changed

7 files changed

+76
-0
lines changed

src/Nest/DSL/PutMappingDescriptor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,20 @@ public PutMappingDescriptor<T> RoutingField(Func<RoutingFieldMappingDescriptor<T
265265
Self.Mapping.RoutingFieldMapping = routingMapper(new RoutingFieldMappingDescriptor<T>());
266266
return this;
267267
}
268+
268269
public PutMappingDescriptor<T> TimestampField(Func<TimestampFieldMappingDescriptor<T>, ITimestampFieldMapping> timestampMapper)
269270
{
270271
timestampMapper.ThrowIfNull("timestampMapper");
271272
Self.Mapping.TimestampFieldMapping = timestampMapper(new TimestampFieldMappingDescriptor<T>());
272273
return this;
273274
}
275+
276+
public PutMappingDescriptor<T> FieldNamesField(Func<FieldNamesFieldMappingDescriptor<T>, IFieldNamesFieldMapping> fieldNamesMapper)
277+
{
278+
Self.Mapping.FieldNamesFieldMapping = fieldNamesMapper == null ? null : fieldNamesMapper(new FieldNamesFieldMappingDescriptor<T>());
279+
return this;
280+
}
281+
274282
public PutMappingDescriptor<T> TtlField(Func<TtlFieldMappingDescriptor, ITtlFieldMapping> ttlFieldMapper)
275283
{
276284
ttlFieldMapper.ThrowIfNull("ttlFieldMapper");
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using System.Linq.Expressions;
4+
using Nest.Resolvers.Converters;
5+
6+
namespace Nest
7+
{
8+
[JsonConverter(typeof(ReadAsTypeConverter<FieldNamesFieldMapping>))]
9+
public interface IFieldNamesFieldMapping : ISpecialField
10+
{
11+
[JsonProperty("enabled")]
12+
bool Enabled { get; set; }
13+
}
14+
15+
public class FieldNamesFieldMapping : IFieldNamesFieldMapping
16+
{
17+
public bool Enabled { get; set; }
18+
}
19+
20+
21+
public class FieldNamesFieldMappingDescriptor<T> : IFieldNamesFieldMapping
22+
{
23+
private IFieldNamesFieldMapping Self { get { return this; } }
24+
25+
bool IFieldNamesFieldMapping.Enabled { get; set;}
26+
27+
public FieldNamesFieldMappingDescriptor<T> Enabled(bool enabled = true)
28+
{
29+
Self.Enabled = enabled;
30+
return this;
31+
}
32+
33+
}
34+
}

src/Nest/Domain/Mapping/Types/RootObjectMapping.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class RootObjectMapping : ObjectMapping
6565
[JsonProperty("_timestamp")]
6666
public ITimestampFieldMapping TimestampFieldMapping { get; set; }
6767

68+
[JsonProperty("_field_names")]
69+
public IFieldNamesFieldMapping FieldNamesFieldMapping { get; set; }
70+
6871
[JsonProperty("_ttl")]
6972
public ITtlFieldMapping TtlFieldMappingDescriptor { get; set; }
7073

src/Nest/Nest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<Compile Include="Domain\Geo\MultiPolygonGeoShape.cs" />
154154
<Compile Include="Domain\Geo\PointGeoShape.cs" />
155155
<Compile Include="Domain\Geo\PolygonGeoShape.cs" />
156+
<Compile Include="Domain\Mapping\SpecialFields\FieldNamesMapping.cs" />
156157
<Compile Include="Domain\Mapping\SubMappings\FieldData\FieldDataFilter.cs" />
157158
<Compile Include="Domain\Mapping\SubMappings\FieldData\FieldDataFrequencyFilter.cs" />
158159
<Compile Include="Domain\Mapping\SubMappings\FieldData\FieldDataMapping.cs" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using NUnit.Framework;
2+
using Nest.Tests.MockData.Domain;
3+
using System.Reflection;
4+
5+
namespace Nest.Tests.Unit.Core.Map.FieldNamesField
6+
{
7+
[TestFixture]
8+
public class FieldNamesFieldTests : BaseJsonTests
9+
{
10+
[Test]
11+
public void FieldNamesMapping()
12+
{
13+
var result = this._client.Map<ElasticsearchProject>(m => m
14+
.FieldNamesField(a => a .Enabled(false))
15+
);
16+
this.JsonEquals(result.ConnectionStatus.Request, MethodBase.GetCurrentMethod());
17+
}
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"elasticsearchprojects": {
3+
"_field_names": {
4+
"enabled": false
5+
}
6+
}
7+
}

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<None Include="Core\Map\Properties\MultiFieldPropertyWithJustNamePath.json">
200200
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
201201
</None>
202+
<Compile Include="Core\Map\FieldNamesField\FieldNamesFieldTests.cs" />
202203
<Compile Include="Core\MultiPercolate\MultiPercolateTests.cs" />
203204
<Compile Include="Core\Map\Transform\MappingTansformTests.cs" />
204205
<Compile Include="Core\Repository\RestoreTests.cs" />
@@ -637,6 +638,9 @@
637638
<None Include="Core\Map\MetaField\MetaFieldSerializes.json">
638639
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
639640
</None>
641+
<None Include="Core\Map\FieldNamesField\FieldNamesMapping.json">
642+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
643+
</None>
640644
<None Include="Core\Map\Transform\MultipleTransforms.json">
641645
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
642646
</None>

0 commit comments

Comments
 (0)