Skip to content

Commit 29fd2c8

Browse files
unknownMpdreamz
authored andcommitted

File tree

7 files changed

+161
-2
lines changed

7 files changed

+161
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public MultiFieldMappingDescriptor<T> Name(string name)
1515
return this;
1616
}
1717

18+
public MultiFieldMappingDescriptor<T> Path(MultiFieldMappingPath path)
19+
{
20+
this._Mapping.Path = path.Value;
21+
return this;
22+
}
23+
1824
public MultiFieldMappingDescriptor<T> Name(Expression<Func<T, object>> objectPath)
1925
{
2026
this._Mapping.Name = objectPath;
@@ -37,4 +43,6 @@ public MultiFieldMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, C
3743
}
3844

3945
}
46+
47+
4048
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public virtual TypeNameMarker Type
2121
set { _typeOverride = value; }
2222
}
2323

24+
[JsonProperty("path")]
25+
public string Path { get; set; }
26+
2427
[JsonProperty("similarity")]
2528
public string Similarity { get; set; }
2629

@@ -36,4 +39,35 @@ public MultiFieldMapping()
3639
this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
3740
}
3841
}
42+
43+
public class MultiFieldMappingPath
44+
{
45+
public MultiFieldMappingPath()
46+
{
47+
48+
}
49+
50+
public MultiFieldMappingPath(string customValue)
51+
{
52+
Value = customValue;
53+
}
54+
55+
public string Value { get; private set; }
56+
57+
public static MultiFieldMappingPath Full
58+
{
59+
get
60+
{
61+
return new MultiFieldMappingPath("full");
62+
}
63+
}
64+
65+
public static MultiFieldMappingPath JustName
66+
{
67+
get
68+
{
69+
return new MultiFieldMappingPath("just_name");
70+
}
71+
}
72+
}
3973
}

src/Tests/Nest.Tests.Integration/Core/Map/Properties/PropertiesTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,43 @@ public void MultiFieldProperty()
195195
);
196196
this.DefaultResponseAssertations(result);
197197
}
198+
199+
[Test]
200+
public void MultiFieldPropertyWithFullNamePath()
201+
{
202+
var result = this._client.Map<ElasticsearchProject>(m => m
203+
.Properties(props => props
204+
.MultiField(s => s
205+
.Path(MultiFieldMappingPath.Full)
206+
.Name(p => p.Name)
207+
.Fields(pprops => pprops
208+
.String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.not_analyzed))
209+
.String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
210+
)
211+
)
212+
)
213+
);
214+
this.DefaultResponseAssertations(result);
215+
}
216+
217+
[Test]
218+
public void MultiFieldPropertyWithJustNamePath()
219+
{
220+
var result = this._client.Map<ElasticsearchProject>(m => m
221+
.Properties(props => props
222+
.MultiField(s => s
223+
.Path(MultiFieldMappingPath.JustName)
224+
.Name(p => p.Name)
225+
.Fields(pprops => pprops
226+
.String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.not_analyzed))
227+
.String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
228+
)
229+
)
230+
)
231+
);
232+
this.DefaultResponseAssertations(result);
233+
}
234+
198235
[Test]
199236
public void IPProperty()
200237
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"name": {
5+
"type": "multi_field",
6+
"path": "full",
7+
"fields": {
8+
"name": {
9+
"type": "string",
10+
"index": "not_analyzed"
11+
},
12+
"searchable": {
13+
"type": "string",
14+
"index": "analyzed"
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"elasticsearchprojects": {
3+
"properties": {
4+
"name": {
5+
"type": "multi_field",
6+
"path": "just_name",
7+
"fields": {
8+
"name": {
9+
"type": "string",
10+
"index": "not_analyzed"
11+
},
12+
"searchable": {
13+
"type": "string",
14+
"index": "analyzed"
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}

src/Tests/Nest.Tests.Unit/Core/Map/Properties/PropertiesTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,44 @@ public void MultiFieldProperty()
180180
)
181181
);
182182
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
183-
}
183+
}
184+
185+
[Test]
186+
public void MultiFieldPropertyWithFullPath()
187+
{
188+
var result = this._client.Map<ElasticsearchProject>(m => m
189+
.Properties(props => props
190+
.MultiField(s => s
191+
.Name(p => p.Name)
192+
.Path(MultiFieldMappingPath.Full)
193+
.Fields(pprops => pprops
194+
.String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.not_analyzed))
195+
.String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
196+
)
197+
)
198+
)
199+
);
200+
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
201+
}
202+
203+
[Test]
204+
public void MultiFieldPropertyWithJustNamePath()
205+
{
206+
var result = this._client.Map<ElasticsearchProject>(m => m
207+
.Properties(props => props
208+
.MultiField(s => s
209+
.Name(p => p.Name)
210+
.Path(MultiFieldMappingPath.JustName)
211+
.Fields(pprops => pprops
212+
.String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.not_analyzed))
213+
.String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
214+
)
215+
)
216+
)
217+
);
218+
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
219+
}
220+
184221
[Test]
185222
public void IPProperty()
186223
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Compile Include="Core\Bulk\BulkTests.cs" />
122122
<Compile Include="Core\Bulk\BulkUrlTests.cs" />
123123
<Compile Include="Core\Map\MappingBehaviourTests.cs" />
124+
<Content Include="Core\Map\Properties\MultiFieldPropertyWithJustNamePath.json" />
124125
<Compile Include="Core\Scroll\ScrollRequestTests.cs" />
125126
<Compile Include="Core\Domain\Connection\ConnectionTests.cs" />
126127
<Compile Include="Core\MultiSearch\MultiSearchTests.cs" />
@@ -953,7 +954,9 @@
953954
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
954955
</None>
955956
</ItemGroup>
956-
<ItemGroup />
957+
<ItemGroup>
958+
<Content Include="Core\Map\Properties\MultiFieldPropertyWithFullPath.json" />
959+
</ItemGroup>
957960
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
958961
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
959962
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)