-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Wrong mapping for nested documents produced by OpenSearch.Client #379
Comments
Hi @DumboJet, The correct way to get your desired mapping with the fluent-mapping API is like so: var res = await client.Indices.CreateAsync(index, i => i.Map<Document>(m => m
.AutoMap()
.Properties(p => p
.Text(t => t
.Name(d => d.Title)
.Index(false))
.Text(t => t
.Name(d => d.Comments)
.Store())
.Object<Pages>(o => o
.Name(d => d.Pages)
.AutoMap()
.Properties(pp => pp
.Text(t => t
.Name(pg => pg.Content)
.Store())
))
.Object<Errata>(o => o
.Name(d => d.Errata)
.AutoMap()
.Properties(pp => pp
.Text(t => t
.Name(e => e.Content)
.Store())
))))); This obviously can get a bit verbose, so you could also achieve this by modifying your document classes like so: public class Document
{
public int Id { get; set; }
[Text(Index = false)]
public string Title { get; set; }
[Text(Store = true)]
public string Comments { get; set; }
public IEnumerable<Pages> Pages { get; set; }
public IEnumerable<Errata> Errata { get; set; }
}
public class Pages
{
public int Number { get; set; }
[Text(Store = true)]
public string Content { get; set; }
}
public class Errata
{
[Text(Store = true)]
public string Content { get; set; }
} Then you can just use var res = await client.Indices.CreateAsync(
index, i => i
.Map<Document>(m => m
.AutoMap())); Additionally could you please make a separate issue for your concerns around nullable int mapping? |
Oh, thanks for this! |
Here is the new bug: #380 |
What if Pages is a single record and not IEnumerable.
How can we achieve nested object. Currently, I am getting this error
|
@assadnazar The required mapping would be identical, OpenSearch does not differentiate between single-value and multi-value properties in mappings. Your particular exception is because the mapping on your index specifies that the |
What is the bug?
When mapping nested documents with
OpenSearch.Client
, the generated mappings appear wrong.How can one reproduce the bug?
Run this code:
And here is the definition of
Document
:What is the expected behavior?
I expect a mapping like this to be generated:
Using
OpenSearch.Client
and the C# code above, I get this mapping, instead:If I manually go and create the mapping like this, it seems to work fine:
If I try to use strings (instead of lamdas) for specifying the fields in the C# code, like this:
...then I get exceptions because fields are mapped twice with conflicting
store
configurations.This is the exception message:
And this is the mapping the library creates:
What is your host/environment?
Windows 11
OpenSearch.Client nuget version 1.5.0
OpenSearch Version: 2.9.0
OpenSearch Security Version: 2.9.0.0
Some extra notes:
.Index(true).Store(true)
from the C# mapping code, the duplicate mappings go away when using field names instead of lamdas. But I need to set thestore
flag, so this is not an option for me.Also, there is another bug, somewhat related to this issue:
When mapping a nullable object property like
public int? Value { get; set; }
the mapper correctly maps this field into an integer.But when you map an array of nullable objects like
public IEnumerable<int?> Values { get; set; }
then it maps the nullable class members instead, like this:The text was updated successfully, but these errors were encountered: