-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
9.xRelates to a 9.x client versionRelates to a 9.x client versionCategory: QuestionState: Awaiting Response
Description
Elastic.Clients.Elasticsearch version: 9.2.1
Elasticsearch version: 9.2
.NET runtime version: 9.0
Operating system version: Windows 11
Migrating to elasticsearch 9 I can not see how to get this code working to create an index (which was working in version 7). Have updated code to match v9 client as best possible, however there are still these errors.
I have tried two different ways to solve, and put in ERROR details where the build error is occurring.
using Elastic.Clients.Elasticsearch;
using System;
using System.Collections.Generic;
namespace ElasticsearchNestedMappingTest
{
// Simple document classes
public class TestDocument
{
public string Id { get; set; }
public List<TestPropertyDocument> Properties { get; set; }
}
public class TestPropertyDocument
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
// Update with your Elasticsearch connection settings
var settings = new ElasticsearchClientSettings(new Uri("http://localhost:9200"));
var client = new ElasticsearchClient(settings);
var indexName = "test-nested-mapping-index";
try
{
Console.WriteLine("Attempting to create index with nested properties mapping...");
// Test 1: With type argument (your current code)
Console.WriteLine("\n=== Test 1: With type argument ===");
try
{
var response1 = await client.Indices.CreateAsync(
$"{indexName}-test1",
c => c
.Mappings(ms => ms
.Properties<TestDocument>(props => props
.Keyword(p => p.Id)
.Nested(p => p.Properties, n => n
.Properties<TestPropertyDocument>(np => np // <== ERROR: The non-generic method 'NestedPropertyDescriptor<TestDocument>.Properties(Properties?)' cannot be used with type arguments
.Keyword(p => p.Id)
.Keyword(p => p.Name)
.Text(p => p.Value, t => t
.Fields(f => f.Keyword("keyword", k => k.IgnoreAbove(256)))
)
)
)
)
)
);
if (response1.Acknowledged)
{
Console.WriteLine("✓ SUCCESS: Index created with type argument syntax!");
}
else
{
Console.WriteLine("✗ FAILED: Index creation not acknowledged");
Console.WriteLine($"Debug: {response1.DebugInformation}");
}
}
catch (Exception ex)
{
Console.WriteLine($"✗ ERROR with type argument: {ex.Message}");
Console.WriteLine($"Type: {ex.GetType().Name}");
}
// Test 2: Without type argument (inferred)
Console.WriteLine("\n=== Test 2: Without type argument (inferred) ===");
try
{
var response2 = await client.Indices.CreateAsync(
$"{indexName}-test2",
c => c
.Mappings(ms => ms
.Properties<TestDocument>(props => props
.Keyword(p => p.Id)
.Nested(p => p.Properties, n => n
.Properties(np => np
.Keyword(p => p.Id)
.Keyword(p => p.Name) // <=== ERROR: 'TestDocument' does not contain a definition for 'Name'
.Text(p => p.Value, t => t // <=== ERROR: 'TestDocument' does not contain a definition for 'Value'
.Fields(f => f.Keyword("keyword", k => k.IgnoreAbove(256)))
)
)
)
)
)
);
if (response2.Acknowledged)
{
Console.WriteLine("✓ SUCCESS: Index created without type argument (inferred)!");
}
else
{
Console.WriteLine("✗ FAILED: Index creation not acknowledged");
Console.WriteLine($"Debug: {response2.DebugInformation}");
}
}
catch (Exception ex)
{
Console.WriteLine($"✗ ERROR without type argument: {ex.Message}");
Console.WriteLine($"Type: {ex.GetType().Name}");
}
// Cleanup - delete test indices
Console.WriteLine("\n=== Cleanup ===");
try
{
await client.Indices.DeleteAsync($"{indexName}-test1");
await client.Indices.DeleteAsync($"{indexName}-test2");
Console.WriteLine("Test indices deleted.");
}
catch { }
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine($"Fatal error: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
}
}
}
}
build errors:
Severity Code Description Project File Line Suppression State Details
Error (active) CS1061 'TestDocument' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'TestDocument' could be found (are you missing a using directive or an assembly reference?) ElasticsearchNestedMappingTest C:\src-TEST\ElasticsearchNestedMappingTest\ElasticsearchNestedMappingTest\Program.cs 86
Error (active) CS1061 'TestDocument' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'TestDocument' could be found (are you missing a using directive or an assembly reference?) ElasticsearchNestedMappingTest C:\src-TEST\ElasticsearchNestedMappingTest\ElasticsearchNestedMappingTest\Program.cs 87
Error (active) CS0308 The non-generic method 'NestedPropertyDescriptor<TestDocument>.Properties(Properties?)' cannot be used with type arguments ElasticsearchNestedMappingTest C:\src-TEST\ElasticsearchNestedMappingTest\ElasticsearchNestedMappingTest\Program.cs 46
Metadata
Metadata
Assignees
Labels
9.xRelates to a 9.x client versionRelates to a 9.x client versionCategory: QuestionState: Awaiting Response