Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Elasticsearch.Net
///Generated of commit @Model.Commit
///</pre>
///</summary>
public interface IElasticsearchClient
public partial interface IElasticsearchClient
{
//IConnection Connection { get; }
//IConnectionConfigurationValues Settings { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Elasticsearch.Net/Elasticsearch.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="Domain\Response\ElasticsearchServerError.cs" />
<Compile Include="Exceptions\OneToOneServerException.cs" />
<Compile Include="Exceptions\ElasticsearchAuthenticationException.cs" />
<Compile Include="IElasticsearchClient.cs" />
<Compile Include="Obsolete\IndicesDeleteAlias.cs" />
<Compile Include="Obsolete\IndicesPutAlias.cs" />
<Compile Include="Obsolete\IndicesRecoveryStatus.cs" />
Expand Down
23 changes: 1 addition & 22 deletions src/Elasticsearch.Net/IElasticsearchClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Elasticsearch.Net
///Generated of commit
///</pre>
///</summary>
public interface IElasticsearchClient
public partial interface IElasticsearchClient
{
//IConnection Connection { get; }
//IConnectionConfigurationValues Settings { get; }
Expand Down Expand Up @@ -20080,26 +20080,5 @@ public interface IElasticsearchClient

Task<ElasticsearchResponse<DynamicDictionary>> UpdateAsync(string index, string type, string id, object body, Func<UpdateRequestParameters, UpdateRequestParameters> requestParameters = null);

/// <summary>
/// Perform any request you want over the configured IConnection synchronously while taking advantage of the cluster failover.
/// </summary>
/// <typeparam name="T">The type representing the response JSON</typeparam>
/// <param name="method">the HTTP Method to use</param>
/// <param name="path">The path of the the url that you would like to hit</param>
/// <param name="data">The body of the request, string and byte[] are posted as is other types will be serialized to JSON</param>
/// <param name="requestParameters">Optionally configure request specific timeouts, headers</param>
/// <returns>An ElasticsearchResponse of T where T represents the JSON response body</returns>
ElasticsearchResponse<T> DoRequest<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);

/// <summary>
/// Perform any request you want over the configured IConnection asynchronously while taking advantage of the cluster failover.
/// </summary>
/// <typeparam name="T">The type representing the response JSON</typeparam>
/// <param name="method">the HTTP Method to use</param>
/// <param name="path">The path of the the url that you would like to hit</param>
/// <param name="data">The body of the request, string and byte[] are posted as is other types will be serialized to JSON</param>
/// <param name="requestParameters">Optionally configure request specific timeouts, headers</param>
/// <returns>A task of ElasticsearchResponse of T where T represents the JSON response body</returns>
Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);
}
}
34 changes: 34 additions & 0 deletions src/Elasticsearch.Net/IElasticsearchClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Elasticsearch.Net
{
public partial interface IElasticsearchClient
{
/// <summary>
/// Perform any request you want over the configured IConnection synchronously while taking advantage of the cluster failover.
/// </summary>
/// <typeparam name="T">The type representing the response JSON</typeparam>
/// <param name="method">the HTTP Method to use</param>
/// <param name="path">The path of the the url that you would like to hit</param>
/// <param name="data">The body of the request, string and byte[] are posted as is other types will be serialized to JSON</param>
/// <param name="requestParameters">Optionally configure request specific timeouts, headers</param>
/// <returns>An ElasticsearchResponse of T where T represents the JSON response body</returns>
ElasticsearchResponse<T> DoRequest<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);

/// <summary>
/// Perform any request you want over the configured IConnection asynchronously while taking advantage of the cluster failover.
/// </summary>
/// <typeparam name="T">The type representing the response JSON</typeparam>
/// <param name="method">the HTTP Method to use</param>
/// <param name="path">The path of the the url that you would like to hit</param>
/// <param name="data">The body of the request, string and byte[] are posted as is other types will be serialized to JSON</param>
/// <param name="requestParameters">Optionally configure request specific timeouts, headers</param>
/// <returns>A task of ElasticsearchResponse of T where T represents the JSON response body</returns>
Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);

}
}
49 changes: 34 additions & 15 deletions src/Nest/Domain/Responses/GetMappingResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ namespace Nest
{
public interface IGetMappingResponse : IResponse
{
Dictionary<string, IList<TypeMapping>> Mappings { get; }
RootObjectMapping Mapping { get; }
void Accept(IMappingVisitor visitor);
}

public class TypeMapping
{
public string TypeName { get; internal set; }
public RootObjectMapping Mapping { get; internal set; }
}

internal class GetRootObjectMappingWrapping : Dictionary<string, Dictionary<string, Dictionary<string, RootObjectMapping>>>
{

Expand All @@ -21,31 +28,43 @@ public class GetMappingResponse : BaseResponse, IGetMappingResponse
public GetMappingResponse()
{
this.IsValid = true;
this.Mappings = new Dictionary<string, IList<TypeMapping>>();
}


internal GetMappingResponse(IElasticsearchResponse status, GetRootObjectMappingWrapping dict)
{
this.Mappings = new Dictionary<string, IList<TypeMapping>>();
this.IsValid = status.Success && dict != null && dict.Count > 0;
if (!this.IsValid) return;
var firstNode = dict.First();
if (!firstNode.Value.HasAny())
return;
var mappingNode = firstNode.Value["mappings"];
if (mappingNode == null)
foreach (var index in dict)
{
this.IsValid = false;
return;
}
var mapping = mappingNode.First();
if (mapping.Value == null)
{
this.IsValid = false;
return;
if (index.Value == null || !index.Value.ContainsKey("mappings"))
continue;

var mappings = index.Value["mappings"];
this.Mappings.Add(index.Key, new List<TypeMapping>());
if (mappings == null) continue;
foreach (var mapping in mappings)
{
if (mapping.Value == null) continue;
var typeMapping = new TypeMapping
{
TypeName = mapping.Key,
Mapping = mapping.Value
};
mapping.Value.Name = mapping.Key;
this.Mappings[index.Key].Add(typeMapping);
}
}
mapping.Value.Name = mapping.Key;
this.Mapping = mapping.Value;

this.Mapping = this.Mappings.Where(kv=>kv.Value.HasAny(v=>v.Mapping != null))
.SelectMany(kv=>kv.Value)
.Select(tm=>tm.Mapping)
.FirstOrDefault(t=>t != null);
}

public Dictionary<string, IList<TypeMapping>> Mappings { get; internal set; }
public RootObjectMapping Mapping { get; internal set; }

public void Accept(IMappingVisitor visitor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using FluentAssertions;
using Nest.Tests.MockData;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;

Expand All @@ -24,18 +25,19 @@ public void Missing()

[Test]
public void Filter()
{
{
var lookFor = NestTestData.Data.Select(p => p.Country).First();
var results = this.Client.Search<ElasticsearchProject>(s=>s
.Size(0)
.Aggregations(a=>a
.Filter("filtered_agg", m=>m
.Filter(f=>f.Term(p=>p.Country, "Sweden"))
.Filter(f=>f.Term(p=>p.Country, lookFor))
)
)
);
results.IsValid.Should().BeTrue();
var filteredBucket = results.Aggs.Filter("filtered_agg");
filteredBucket.DocCount.Should().BeGreaterThan(1);
filteredBucket.DocCount.Should().BeGreaterThan(0);
}

[Test]
Expand Down
4 changes: 3 additions & 1 deletion src/Tests/Nest.Tests.Integration/Core/CountTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Nest.Tests.MockData;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;
using System;
Expand All @@ -24,11 +25,12 @@ public void CountTest()
[Test]
public void CountWithQueryTest()
{
var lookFor = NestTestData.Data.Select(p => p.Country).First();
var response = this.Client.Count<ElasticsearchProject>(c => c
.Query(q => q
.Match(m => m
.OnField(p => p.Country)
.Query("Sweden")
.Query(lookFor)
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void SingleTransformTest()
.Index(ElasticsearchConfiguration.DefaultIndex)
);

getResult.Mapping.Transform.Count.Should().Be(1);
getResult.Mapping.Transform.Count.Should().BeGreaterOrEqualTo(1);
}

[Test]
Expand Down
3 changes: 2 additions & 1 deletion src/Tests/Nest.Tests.Integration/Core/UpdateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using FluentAssertions;
using Nest.Tests.MockData;
using NUnit.Framework;
using Nest.Tests.MockData.Domain;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void TestUpdate_ObjectInitializer()
Script = "ctx._source.loc += 10",
});
project = this.Client.Source<ElasticsearchProject>(s => s.Id(id));
Assert.AreEqual(project.LOC, loc + 10);
project.LOC.Should().Be(loc + 10);
Assert.AreNotEqual(project.Version, "1");
}

Expand Down
149 changes: 149 additions & 0 deletions src/Tests/Nest.Tests.Integration/Mapping/GetMultipleMappingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;

namespace Nest.Tests.Integration.Mapping
{
[TestFixture]
public class GetMultipleMappingTests : IntegrationTests
{
private void TestElasticsearchProjectMapping(RootObjectMapping typeMapping)
{
Assert.NotNull(typeMapping);
Assert.AreEqual("string", typeMapping.Properties["content"].Type.Name);
Assert.AreEqual("string", typeMapping.Properties["country"].Type.Name);
Assert.AreEqual("double", typeMapping.Properties["doubleValue"].Type.Name);
Assert.AreEqual("long", typeMapping.Properties["longValue"].Type.Name);
Assert.AreEqual("boolean", typeMapping.Properties["boolValue"].Type.Name);
Assert.AreEqual("integer", typeMapping.Properties["intValues"].Type.Name);
Assert.AreEqual("float", typeMapping.Properties["floatValues"].Type.Name);
Assert.AreEqual("string", typeMapping.Properties["name"].Type.Name);
Assert.AreEqual("date", typeMapping.Properties["startedOn"].Type.Name);
Assert.AreEqual("long", typeMapping.Properties["stupidIntIWantAsLong"].Type.Name);
Assert.AreEqual("float", typeMapping.Properties["floatValue"].Type.Name);
Assert.AreEqual("integer", typeMapping.Properties["id"].Type.Name);
Assert.AreEqual("integer", typeMapping.Properties["loc"].Type.Name);
Assert.AreEqual("geo_point", typeMapping.Properties["origin"].Type.Name);
Assert.AreEqual("object", typeMapping.Properties["product"].Type.Name);

var productMapping = typeMapping.Properties["product"] as ObjectMapping;
Assert.NotNull(productMapping);
Assert.AreEqual("string", productMapping.Properties["name"].Type.Name);
Assert.AreEqual("string", productMapping.Properties["id"].Type.Name);

var countryMapping = typeMapping.Properties["country"] as StringMapping;
Assert.NotNull(countryMapping);
Assert.AreEqual(FieldIndexOption.NotAnalyzed, countryMapping.Index);
}

private void TestPersonMapping(RootObjectMapping typeMapping)
{
Assert.NotNull(typeMapping);
Assert.AreEqual("string", typeMapping.Properties["email"].Type.Name);
var firstNameMapping = typeMapping.Properties["email"] as StringMapping;
firstNameMapping.Should().NotBeNull();
firstNameMapping.Index.Should().Be(FieldIndexOption.NotAnalyzed);
}

[Test]
public void GetSameMappingFromTwoDifferentIndices()
{
var indices = new[]
{
ElasticsearchConfiguration.NewUniqueIndexName(),
ElasticsearchConfiguration.NewUniqueIndexName()
};

var x = this.Client.CreateIndex(indices.First(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

x = this.Client.CreateIndex(indices.Last(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

var response = this.Client.GetMapping<ElasticsearchProject>(i => i
.Index(string.Join(",", indices))
.Type("elasticsearchprojects")
);
response.Should().NotBeNull();
response.Mappings.Should().NotBeEmpty()
.And.HaveCount(2);
foreach (var indexMapping in response.Mappings)
{
var indexName = indexMapping.Key;
indices.Should().Contain(indexName);
var mappings = indexMapping.Value;
mappings.Should().NotBeEmpty().And.HaveCount(1);
foreach (var mapping in mappings)
{
mapping.TypeName.Should().Be("elasticsearchprojects");
TestElasticsearchProjectMapping(mapping.Mapping);
}
}


}

[Test]
public void GetDifferentMappingsFromMultipleIndices()
{
var indices = new[]
{
ElasticsearchConfiguration.NewUniqueIndexName(),
ElasticsearchConfiguration.NewUniqueIndexName()
};

var x = this.Client.CreateIndex(indices.First(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
.AddMapping<Person>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

x = this.Client.CreateIndex(indices.Last(), s => s
.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
.AddMapping<GeoLocation>(m => m.MapFromAttributes())
);
Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

var response = this.Client.GetMapping(new GetMappingRequest(string.Join(",", indices), "*"));
response.Should().NotBeNull();
response.Mappings.Should().NotBeEmpty()
.And.HaveCount(2);
foreach (var indexMapping in response.Mappings)
{
var indexName = indexMapping.Key;
indices.Should().Contain(indexName);
var mappings = indexMapping.Value;
mappings.Should().NotBeEmpty().And.HaveCount(2);
mappings.Should().Contain(m => m.TypeName == "elasticsearchprojects")
.And.Contain(m=>m.TypeName == (indexName == indices.First() ? "person" : "geolocation"));
foreach (var mapping in mappings)
{
switch (mapping.TypeName)
{
case "elasticsearchprojects":
TestElasticsearchProjectMapping(mapping.Mapping);
break;
case "person":
TestPersonMapping(mapping.Mapping);
break;
case "geolocation":
break;
default:
Assert.Fail("Unexpected mapping found {0}", mapping.TypeName);
break;
}
}
}


}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<Compile Include="Indices\StatsTests.cs" />
<Compile Include="Core\AsyncTests.cs" />
<Compile Include="Mapping\MappingVisitorTests.cs" />
<Compile Include="Mapping\GetMultipleMappingTests.cs" />
<Compile Include="Reproduce\Reproduce769Tests.cs" />
<Compile Include="Reproduce\Reproduce945Tests.cs" />
<Compile Include="Reproduce\Reproduce953Tests.cs" />
Expand Down
Loading