Skip to content

Commit 23e011d

Browse files
committed
Merge branch 'develop' of https://github.com/elasticsearch/elasticsearch-net into develop
2 parents 7518ed5 + 8268d60 commit 23e011d

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

src/Nest/Domain/Mapping/Descriptors/PropertiesDescriptor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Reflection;
34
using Nest.Resolvers;
45
using Nest.Resolvers.Converters;
56
using Elasticsearch.Net;
@@ -167,6 +168,16 @@ public PropertiesDescriptor<T> Completion(Func<CompletionMappingDescriptor<T>, C
167168
return this;
168169
}
169170

171+
public PropertiesDescriptor<T> Custom(IElasticType customMapping)
172+
{
173+
customMapping.ThrowIfNull("customMapping");
174+
if (customMapping.Name.IsConditionless())
175+
throw new Exception("Could not get field name for custom mapping");
176+
177+
178+
this.Properties.Add(customMapping.Name, customMapping);
179+
return this;
180+
}
170181
//Reminder if you are adding a new mapping type, may one appear in the future
171182
//Add them to PropertiesDescriptor, CorePropertiesDescriptor (if its a new core type), SingleMappingDescriptor
172183
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Nest.Tests.MockData.Domain;
5+
using NUnit.Framework;
6+
7+
namespace Nest.Tests.Unit.Core.Map.CustomMapping
8+
{
9+
[TestFixture]
10+
public class ImagePluginMappingTests : BaseJsonTests
11+
{
12+
13+
public class ImagePluginType : IElasticType
14+
{
15+
public PropertyNameMarker Name { get; set; }
16+
public TypeNameMarker Type { get { return "image"; } }
17+
18+
19+
public IDictionary<string, object> Feature { get; set; }
20+
public IDictionary<string, object> MetaData { get; set; }
21+
}
22+
23+
[Test]
24+
public void RepresentUnknowImageMappingPlugin()
25+
{
26+
var imagePluginMapping = new ImagePluginType()
27+
{
28+
Name = "my_img",
29+
Feature = new Dictionary<string, object>
30+
{
31+
{ "CEDD", new { hash = "BIT_SAMPLING"} },
32+
{ "JCD", new { hash = new [] {"BIT_SAMPLING", "LSH"}} }
33+
},
34+
MetaData = new Dictionary<string, object>
35+
{
36+
37+
{ "jpeg.image_width", new {
38+
type = "string",
39+
store = "yes"
40+
}
41+
},
42+
{ "jpeg.image_height", new {
43+
type= "string",
44+
store= "yes"
45+
}
46+
}
47+
}
48+
};
49+
50+
var result = this._client.Map<ElasticsearchProject>(m => m
51+
.Properties(p=>p
52+
.Custom(imagePluginMapping)
53+
)
54+
);
55+
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
56+
}
57+
}
58+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"my_img": {
5+
"name": "my_img",
6+
"type": "image",
7+
"feature": {
8+
"CEDD": {
9+
"hash": "BIT_SAMPLING"
10+
},
11+
"JCD": {
12+
"hash": [
13+
"BIT_SAMPLING",
14+
"LSH"
15+
]
16+
}
17+
},
18+
"metaData": {
19+
"jpeg.image_width": {
20+
"type": "string",
21+
"store": "yes"
22+
},
23+
"jpeg.image_height": {
24+
"type": "string",
25+
"store": "yes"
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<Compile Include="Core\Bulk\BulkTests.cs" />
123123
<Compile Include="Core\Bulk\BulkUrlTests.cs" />
124124
<Compile Include="Core\Indices\Analysis\Analyzers\AnalyzerTests.cs" />
125+
<Compile Include="Core\Map\CustomMapping\ImagePluginMappingTests.cs" />
125126
<Compile Include="Core\Map\MappingBehaviourTests.cs" />
126127
<None Include="Cluster\PutSettings\PutSettings.json">
127128
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -150,6 +151,9 @@
150151
<None Include="Core\Indices\Analysis\Analyzers\PatternAnalyzerTest.json">
151152
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
152153
</None>
154+
<None Include="Core\Map\CustomMapping\RepresentUnknowImageMappingPlugin.json">
155+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
156+
</None>
153157
<None Include="Core\Map\Properties\MultiFieldPropertyWithJustNamePath.json">
154158
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
155159
</None>

0 commit comments

Comments
 (0)